Skip to content

Instantly share code, notes, and snippets.

@luccasiau
Created June 15, 2015 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luccasiau/7ed888e0339d3ecff20e to your computer and use it in GitHub Desktop.
Save luccasiau/7ed888e0339d3ecff20e to your computer and use it in GitHub Desktop.
//
// 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