Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #define max(a,b) \
- ({ __typeof__ (a) _a = (a); \
- __typeof__ (b) _b = (b); \
- _a > _b ? _a : _b; })
- int main(){
- int n = 0, k = 0;
- long max_sum = 0, current_sum = 0;
- int index = 0;
- long value;
- scanf("%d%d",&n,&k);
- long* arr = (long*)malloc(k*sizeof(long));
- while(index < k && 1 == scanf("%ld",&arr[index])){
- current_sum += arr[index];
- index++;
- }
- int ans = 0;
- int arr_index = 0;
- index = 1;
- max_sum = current_sum;
- while(1 == scanf("%ld",&value)){
- current_sum = current_sum - arr[arr_index] + value;
- arr[arr_index] = value;
- if(current_sum > max_sum){
- max_sum = current_sum;
- ans = index;
- }
- arr_index = (arr_index+1)%k;
- index++;
- }
- printf("%d",ans);
- free(arr);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement