时间:2016-03-19 20:58:13 星期六
题目编号:[2016-03-19][UVA][11078][Open Credit System]
题目大意:求一个序列中 Ai - Aj的最大值(i < j)
分析:维护j前面最大的Ai ,更新ans即可
#include <cstdio>#include<algorithm>using namespace std;#define FOR(x,y,z) for(int (x)=(y);(x)<(z);++(x))const int maxn = 100000 + 10;int a[maxn];int main(){ int t,n,maxAi,ans; scanf("%d",&t); while(t--){ scanf("%d",&n); FOR(i,0,n) scanf("%d",a + i); maxAi = a[0]; ans = a[0] - a[1]; FOR(i,1,n){ ans = max(maxAi - a[i],ans); maxAi = max(maxAi,a[i]); } printf("%d\n",ans); } return 0;}