Title: http://www.tyvj.cn/p/1305
Defined:
Sum[i]=a[1]+a[2]+...+a[i] That is, sum[i] is the prefix of sequence A and
Dp[i] = sum[i]-min (sum[j]) (i-j<m) that is, dp[i] for the maximum continuous and the length of the end of I , which is less than M
The
The answer is Max (Dp[i]) (1≤i≤n)
#include <cstdio>#include<iostream>using namespacestd;intsum[300005];intst[300005];intMain () {intN, M, X, L, R, Minn, ans; while(SCANF ("%d%d", &n, &m)! =EOF) { for(intI=1; i<=n; i++) {scanf ("%d", &x); Sum[i]= sum[i-1] +x; }
//Maintain a monotonically incrementing queue L=r=0; St[r++]=0; Ans= sum[1]; for(intI=1; i<=n; i++) { while(L<r && i-st[l] > m) l++; Minn=Sum[st[l]]; if(Ans < sum[i]-minn) ans = sum[i]-Minn; while(L<r && Sum[i] < sum[st[r-1]]) r--; St[r++] =i; } printf ("%d\n", ans); } return 0;}
TYVJ 1305--length not exceeding m maximum continuous and "prefix and + monotone queue"