Skip to content

Instantly share code, notes, and snippets.

@rigibun
Last active December 20, 2015 20:39
Show Gist options
  • Save rigibun/6191938 to your computer and use it in GitHub Desktop.
Save rigibun/6191938 to your computer and use it in GitHub Desktop.
#include<stdio.h>
int main(void){
int i, n, k, sum, max, a[100000];
while(scanf("%d %d", &n, &k), n){
sum = max = 0;
for(i = 0; i < n; i++){
scanf("%d", &a[i]);
if(i < k)
sum+=a[i];
}
max = sum;
for(i = k; i < n; i++){
sum += a[k] - a[k - i];
if(sum > max)
max = sum;
}
printf("%d\n", max);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment