Test instructions
Give a sequence, find two integers a[i],a[j] to make a[i]-a[j] maximum;
Ideas:
Go back to the past; water problem;
AC Code:
#include <bits/stdc++.h>/*#include <vector> #include <iostream> #include <queue> #include <cmath> #include <map > #include <cstring> #include <algorithm> #include <cstdio>*/using namespacestd;#definefor (i,j,n) for (int i=j;i<=n;i++)#defineRiep (n) for (int i=1;i<=n;i++)#defineRIOP (n) for (int i=0;i<n;i++)#defineRJEP (n) for (int j=1;j<=n;j++)#defineRJOP (n) for (int j=0;j<n;j++)#defineMST (SS,B) memset (ss,b,sizeof (ss));typedefLong Longll;template<classT>voidRead (t&num) { CharCH;BOOLf=false; for(Ch=getchar (); ch<'0'|| Ch>'9'; f= ch=='-', ch=GetChar ()); for(num=0; ch>='0'&&ch<='9'; num=num*Ten+ch-'0', ch=GetChar ()); F&& (num=-num);}intstk[ -], Tp;template<classT> Inlinevoidprint (T p) {if(!p) {Puts ("0");return; } while(p) stk[++ TP] = p%Ten, p/=Ten; while(TP) Putchar (stk[tp--] +'0'); Putchar ('\ n');}ConstLL mod=1e9+7;Const DoublePi=acos (-1.0);ConstLL inf=1e18;Const intn=1e5+Ten;Const intmaxn=1005;Const Doubleeps=1e-Ten;intN;intA[n];intMain () {intT; Read (t); while(t--) {read (n); For (I,1, N) read (a[i]); intmmax=a[1],ans=-11000000; For (I,2, N) {ans=max (ans,mmax-A[i]); if(A[i]>mmax) mmax=A[i]; } cout<<ans<<"\ n"; } return 0;}
UVA-11078 (water problem)