Created
June 15, 2015 17:13
-
-
Save luccasiau/7ed888e0339d3ecff20e 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
// | |
// halloween.cpp | |
// | |
// Created by Lucca Siaudzionis on 03/03/15. | |
// | |
// URI 1656 - Doces do Dia das Bruxas | |
#include <cstdio> | |
//------------------ | |
#define MAXN 100100 | |
int c, n; | |
int resto[MAXN]; | |
int candy[MAXN]; | |
//------------------ | |
int main(){ | |
while(scanf("%d %d", &c, &n) && n){ | |
for(int i = 1;i <= n;i++){ | |
scanf("%d", &candy[i]); | |
candy[i] %= c; | |
} | |
for(int i = 1;i <= c;i++) resto[i] = -1; | |
int sum = 0; | |
resto[0] = 0; | |
for(int i = 1;i <= c;i++){ | |
sum += candy[i]; | |
sum %= c; | |
if(resto[sum] != -1){ | |
printf("%d", resto[sum]+1); | |
for(int j = resto[sum]+2;j <= i;j++) printf(" %d", j); | |
printf("\n"); | |
break; | |
} | |
resto[sum] = i; | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment