Created
June 8, 2014 12:50
-
-
Save kokosabu/a4279ea2a73d2af99a83 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
int main() | |
{ | |
int k; | |
int n; | |
int *a; | |
int early_day; /* 候補の中で最も早い開始日 */ | |
int early_sum; /* 連続するk日の訪問者数合計 */ | |
int campaign_count; /* キャンペーンを行った期間の候補数 */ | |
int i, j; | |
int sum; | |
scanf("%d %d", &n, &k); | |
a = (int *)malloc(sizeof(int) * n); | |
for (i = 0; i < n; i++) { | |
scanf("%d", &a[i]); | |
} | |
early_day = -1; | |
early_sum = -1; | |
campaign_count = 0; | |
for (i = 0; i <= (n - k); i++) { | |
sum = 0; | |
for (j = 0; j < k; j++) { | |
sum += a[i+j]; | |
} | |
if (early_sum < sum) { | |
early_day = i + 1; | |
early_sum = sum; | |
campaign_count = 1; | |
} else if (early_sum == sum ) { | |
campaign_count++; | |
} | |
} | |
printf("%d %d\n", campaign_count, early_day); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment