http://codeforces.com/contest/332/problem/B
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #define maxn 200010 5 using namespace std; 6 int a[maxn]; 7 long long sum[maxn]; 8 long long max1; 9 int main() 10 { 11 int n,k; 12 scanf("%d%d",&n,&k); 13 for(int i=0; i<n; i++) 14 { 15 scanf("%d",&a[i]); 16 } 17 for(int i=0; i<n; i++) 18 { 19 if(i<k) sum[0]+=a[i]; 20 else 21 sum[i-k+1]=sum[i-k]-a[i-k]+a[i]; 22 } 23 int aa=0,bb=0,t=0; 24 for(int i=0; i<n-k; i++) 25 { 26 if(sum[i]>sum[t]) t=i; 27 if(sum[t]+sum[i+k]>max1) 28 { 29 max1=sum[t]+sum[i+k]; 30 aa=t; 31 bb=i+k; 32 } 33 } 34 printf("%d %d\n",aa+1,bb+1); 35 return 0; 36 }