UVa11078 - Open Credit System

题目链接

简介:给出一序列,求Ai-Aj最大值(i

//这里写代码片
#include<cstdio>
#include<cstring>
#include<iostream>

using namespace std;

const int INF=1e9;
int n,maxx;

int main()
{
    int T;
    scanf("%d",&T);
    for (int cas=1;cas<=T;cas++)
    {
        scanf("%d",&n);
        int ans;
        for (int i=1;i<=n;i++)
        {
            int x;
            scanf("%d",&x);
            if (i!=1)
            {
                if (i==2) ans=maxx-x;
                else ans=max(ans,maxx-x);
                maxx=max(maxx,x);
            } 
            else maxx=x;
        }
        printf("%d\n",ans);
    }
    return 0;
}
posted @ 2017-10-15 16:39  wtt3117  阅读(92)  评论(0编辑  收藏