Codeforces Round #613 (Div. 2) B

B. Just Eat It!

传送门

#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
 
const int Maxn = 100005;
 
int t;
int n;
int a[Maxn];
 
int main()
{
    scanf("%d", &t);
    while (t--) {
        scanf("%d", &n);
        ll sum1 = 0, mx = -100000000000000007ll;
        map <ll, int> M;
        M[0]++;
        for (int i = 0; i < n; i++) {
            scanf("%d", &a[i]);
            sum1 += a[i];
            if (i == n - 1)
                if (--M[0] == 0) 
                M.erase(0);
            if (!M.empty())
                mx = max(mx, sum1 - M.begin()->first);
            M[sum1]++;
        }
        printf("%s\n", sum1 > mx? "YES": "NO");
    }
    return 0;
}
发布了289 篇原创文章 · 获赞 112 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/king9666/article/details/103948814