标签:
Description
Input
Output
Sample Input
Sample Output
/* * Author: sweat123 * Created Time: 2016/7/11 21:46:18 * File Name: main.cpp */ #include<set> #include<map> #include<queue> #include<stack> #include<cmath> #include<string> #include<vector> #include<cstdio> #include<time.h> #include<cstring> #include<iostream> #include<algorithm> #define INF 1<<30 #define MOD 1000000007 #define ll long long #define lson l,m,rt<<1 #define key_value ch[ch[root][1]][0] #define rson m+1,r,rt<<1|1 #define pi acos(-1.0) using namespace std; const int MAXN = 200010; deque<int>q; int a[MAXN],n,k,sum[MAXN],cnt; int main(){ int t; scanf("%d",&t); while(t--){ q.clear(); scanf("%d%d",&n,&k); for(int i = 1; i <= n; i++){ scanf("%d",&a[i]); } for(int i = 1; i < k; i++){ a[i+n] = a[i]; } sum[0] = 0; for(int i = 1; i < n + k; i++){ sum[i] = sum[i-1] + a[i]; } int ans = -INF,l,r; for(int i = 1; i < n + k; i++){ while(!q.empty() && sum[q.back()] > sum[i-1]){ q.pop_back(); } while(!q.empty() && q.front() < (i - k)){ q.pop_front(); } q.push_back(i-1); int val = sum[i] - sum[q.front()]; if(val > ans){ ans = val; l = q.front(); r = i; } } if(r > n) r %= n; printf("%d %d %d\n",ans,l+1,r); } return 0; }
标签:
原文地址:http://www.cnblogs.com/sweat123/p/5661855.html