Open Credit System UVA - 11078

问题

https://vjudge.net/problem/UVA-11078

分析

类似单调栈,找到j左边比他大的数字,但是不需要建立栈,这里保存最大值就行

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long LL;
const int maxn=100000+5;
int n,t,kase=0;
int main(void){
    scanf("%d",&kase);
    while(kase--){
        scanf("%d",&n);
        int maxv=-1000000,ans=-1;
        for(int i=0;i<n;++i){
            scanf("%d",&t);
            ans=max(maxv-t,ans);
            maxv=max(maxv,t);
        }
        printf("%d\n",ans);
    }
    return 0;
}
发布了180 篇原创文章 · 获赞 3 · 访问量 3483

猜你喜欢

转载自blog.csdn.net/zpf1998/article/details/104685645