Monotonous queue silly questions.
$ I $ consider the answer end: $ max (sumv_ {i} -sumv_ {j}), j \ in [im, i-1] $
($ Sumv_ {i} $ prefix and)
Slightly engage in a practice, found $ sumv_ {i} $ this is fixed.
We only need to maintain $ min (sumv_ {j}) $ can be.
Monotonous queue optimization moment, each taking the first team can be.
Code:
#include<cstdio> #include<deque> #include<algorithm> using namespace std; const int maxn = 500000+3; const int inf = -100000000; long long sumv[maxn]; deque<int>Q; int main() { //freopen("in.txt","r",stdin); int n,m,ans = inf; scanf("%d%d",&n,&m); for(int i =1;i <= n;++i){ int w; scanf("%d",&w); sumv[i] = sumv[i-1]+w; } for(int i =1; i<=n ;++i){ int cur = i- m; while(!Q.empty() && Q.front()<cur)Q.pop_front(); while(!Q.empty() && sumv[Q.back()] >= sumv[i])Q.pop_back(); Q.push_back(i); int h = (int)(sumv[i] - sumv[Q.front()]); years = max (years, h); } Printf ( "% d", year); return 0; }