[2016-03-19][UVA][11078][Open Credit System]

  • 时间:2016-03-19 20:58:13 星期六

  • 题目编号:[2016-03-19][UVA][11078][Open Credit System]

  • 题目大意:求一个序列中 Ai - Aj的最大值(i < j)

  • 分析:维护j前面最大的Ai ,更新ans即可

  1. #include <cstdio>
  2. #include<algorithm>
  3. using namespace std;
  4. #define FOR(x,y,z) for(int (x)=(y);(x)<(z);++(x))
  5. const int maxn = 100000 + 10;
  6. int a[maxn];
  7. int main(){
  8. int t,n,maxAi,ans;
  9. scanf("%d",&t);
  10. while(t--){
  11. scanf("%d",&n);
  12. FOR(i,0,n) scanf("%d",a + i);
  13. maxAi = a[0];
  14. ans = a[0] - a[1];
  15. FOR(i,1,n){
  16. ans = max(maxAi - a[i],ans);
  17. maxAi = max(maxAi,a[i]);
  18. }
  19. printf("%d\n",ans);
  20. }
  21. return 0;
  22. }


来自为知笔记(Wiz)


posted on 2016-03-19 21:14  红洋  阅读(136)  评论(0)    收藏  举报

导航