Skip to content

Instantly share code, notes, and snippets.

@kokosabu kokosabu/B001.c
Created Jun 8, 2014

Embed
What would you like to do?
#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
You can’t perform that action at this time.