Sunday, January 5, 2014

codechef BUYING2 - "buying sweets" solution

codechef BUYING2 - "buying sweets": http://www.codechef.com/problems/BUYING2

codechef BUYING2 - "buying sweets" solution: http://ideone.com/vgD2Hb

#include <iostream>
#include <cstdio>
using namespace std;

int main() {
int t, n, x, b, s, min;
scanf("%d", &t);
while(t--) {
scanf("%d %d", &n, &x);
s=0; min=101;
while(n--) { scanf("%d", &b); s=s+b; if(b<min) min=b; }
if(min<=s%x) printf("-1\n");
else printf("%d\n", s/x);
}
return 0;
}

No comments:

Post a Comment