Original title: UVA11078
Test instructions: Give you an array, set a[], ask for a m=a[i]-a[j],m bigger the better, and I must be less than J
How can I ask? Sort? Requirement I is less than J. Enumeration? Can only say time-out no limit. So iterate over the array, set the first to be a "0", then meet the number of a "0" to update it, and then take this to the meiosis group of each element, but also to constantly update the M value.
#include"Iostream"#include"Set"#include"CString"#include"Cstdio"#include"Algorithm"UsingNamespace Std;Constint MAXN=100000+10;int a[MAXN];IntMain(){int T; Cin>>t;While(T--){int n; Cin>>n;For(int I=0; I<n; I++){cin>>a[I];}int x=a[0];int ans=-1;For(int I=1;i<n;i< Span class= "Sh-symbol" >++) {ans=max< Span class= "Sh-symbol" > (X-a[i],ans=max (A[i< Span class= "Sh-symbol" >],x); Cout<<ans<<endl return 0;< Span class= "Sh-cbracket" >
Fourth week of training (efficient algorithm design) m problem (scanning method)