今天有点头痛就不写具体细节了,贴完走人
#include#include #include #include #include #define rep(i,j,k) for(register int i=j;i<=k;i++)using namespace std;const int maxn = 3e5+11;typedef long long ll;int a[maxn],n,m;ll sum[maxn];int main(){ while(cin>>n>>m){ rep(i,1,n) scanf("%d",&a[i]); rep(i,1,n) sum[i]=sum[i-1]+a[i]; deque que; ll mx=0; rep(i,1,n){ while(!que.empty()&&sum[que.front()]>sum[i]) que.pop_front(); que.push_front(i); while(!que.empty()&&que.back()