#include<bits/stdc++.h> usingnamespace std; int n,t,w,chen_zhe; int a[2000010],sum[2000010],kkksc03[2000010],id[2000010]; intmain(){ //freopen(".in","r",stdin); //freopen(".out","w",stdout); scanf("%d",&n); for (int i = 1; i <= n; i++){ scanf("%d",&a[i]); a[i+n] = a[i]; } for (int i = 1; i <= 2*n; i++){ sum[i] = sum[i-1]+a[i]; } t = w = 1; kkksc03[1] = sum[1]; id[1] = 1; for (int i = 2; i <= n; i++){ while (sum[i] < kkksc03[w]){ w--; if (w < t){ break; } } w++; kkksc03[w] = sum[i]; id[w] = i; } if (kkksc03[t] >= 0){ chen_zhe++; } for (int i = n+1; i <= 2*n-1; i++){ while (id[t] < i-n+1){ t++; if (t > w){ break; } } if (w >= t){ while (sum[i] < kkksc03[w]){ w--; if (w < t){ break; } } } w++; kkksc03[w] = sum[i]; id[w] = i; if (kkksc03[t]-sum[i-n] >= 0){ chen_zhe++; } } printf("%d",chen_zhe); return0; }
测评结果 通过 分数 100 耗时 721 MS 内存 33428 KB 语言 C++ 代码长度 983 bytes