好消息,坏消息
emmm前缀和真香,就是注意h[]解决负数导致的上一个前缀比下一个大
#include<bits/stdc++.h>
using namespace std;
long long n,a[1000010],q[1000010],miq[1000010],h[1000010],ans;
int main() {
scanf("%lld",&n);
miq[0]=1e9;
h[n+1]=1e9;
for (long long i=1; i<=n; i++)
{
scanf("%lld",&a[i]);
q[i]=q[i-1]+a[i];//前缀
miq[i]=min(q[i],miq[i-1]);
}
for(long long i=n; i>=1; i--)
{
h[i]=min(q[i],h[i+1]);
}
for(long long i=1; i<=n; i++)
{
if((h[i]-q[i-1]>=0)&&(miq[i-1]+q[n]-q[i-1]>=0)) ans++;
}
printf("%lld\n",ans);
}
正解单调队列,有待补充