#include<algorithm> (5863)#include<iostream> using namespace std; int S(int s[], int c) { if(c==0) return 0; else return S(s, c-1)+s[c-1]; } int main() { int m; scanf("%d", &m); while(m--) { int a, b, c, d, sum, maxn[100001], j, k, l, M; scanf("%d %d", &a, &b); int s[100001]; for (j = 0; j < a; j++) scanf("%d", &s[j]); for (k = 0; k <= a-2*b+1; k++) { c=S(s, k+b)-S(s, k); maxn[k]=max(maxn[k+1], S(s, k+2*b)-S(s, k+b)); M=max(c+maxn[k], c+maxn[0]); } printf("%d\n", M); } return 0; } 根据题解做的,我不知道该怎么再降低复杂度了,还是时间超限,求求大神们指导一下
牛客网
牛客企业服务