Codeforces Round #235 (Div. 2), problem: (A) Vanya and Cards: http://codeforces.com/contest/401/problem/A
Codeforces Round #235 (Div. 2), problem: (A) Vanya and Cards solution: http://ideone.com/d0UFV7
#include <iostream>
#include <cstdio>
using namespace std;
int main() {
int n, x, b, cnt, a;
b=cnt=0;
scanf("%d%d", &n, &x);
for(int i=0; i<n; i++) {
scanf("%d", &a);
b+=a;
}
while(b!=0) {
if(b>0) {
if(b-x>0) {
cnt++;
b-=x;
}
else {
cnt++;
b=0;
}
}
else {
if(b+x<0) {
cnt++;
b+=x;
}
else {
cnt++;
b=0;
}
}
}
printf("%d\n", cnt);
return 0;
}
No comments:
Post a Comment