codeforces 235 div2 A. Vanya and Cards
2014-03-12 20:37
651 查看
Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each card doesn't exceed x in the absolute value.
Natasha doesn't like when Vanya spends a long time playing, so she hid all of his cards. Vanya became sad and started looking for the cards but he only found n of them. Vanya loves the balance, so he wants the sum of all numbers on found cards equal to zero. On the other hand, he got very tired of looking for cards. Help the boy and say what is the minimum number of cards does he need to find to make the sum equal to zero?
You can assume that initially Vanya had infinitely many cards with each integer number from - x to x.
Input
The first line contains two integers: n (1 ≤ n ≤ 1000) — the number of found cards and x (1 ≤ x ≤ 1000) — the maximum absolute value of the number on a card. The second line contains n space-separated integers — the numbers on found cards. It is guaranteed that the numbers do not exceed x in their absolute value.
Output
Print a single number — the answer to the problem.
Sample test(s)
Input
Output
Input
Output
Note
In the first sample, Vanya needs to find a single card with number -2.
In the second sample, Vanya needs to find two cards with number 2. He can't find a single card with the required number as the numbers on the lost cards do not exceed 3 in their absolute value.
View Code
Natasha doesn't like when Vanya spends a long time playing, so she hid all of his cards. Vanya became sad and started looking for the cards but he only found n of them. Vanya loves the balance, so he wants the sum of all numbers on found cards equal to zero. On the other hand, he got very tired of looking for cards. Help the boy and say what is the minimum number of cards does he need to find to make the sum equal to zero?
You can assume that initially Vanya had infinitely many cards with each integer number from - x to x.
Input
The first line contains two integers: n (1 ≤ n ≤ 1000) — the number of found cards and x (1 ≤ x ≤ 1000) — the maximum absolute value of the number on a card. The second line contains n space-separated integers — the numbers on found cards. It is guaranteed that the numbers do not exceed x in their absolute value.
Output
Print a single number — the answer to the problem.
Sample test(s)
Input
3 2 -1 1 2
Output
1
Input
2 3 -2 -2
Output
2
Note
In the first sample, Vanya needs to find a single card with number -2.
In the second sample, Vanya needs to find two cards with number 2. He can't find a single card with the required number as the numbers on the lost cards do not exceed 3 in their absolute value.
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; int main() { int n,x; while(scanf("%d%d",&n,&x)!=EOF) { int sum = 0,d; for(int i = 1;i <= n;++i) { scanf("%d",&d); sum += d; } sum = abs(sum); int ans = (sum % x == 0? sum / x:sum / x + 1); printf("%d\n",ans); } return 0; }
View Code
相关文章推荐
- Codeforces Round #235 (Div. 2) A. Vanya and Cards
- Codeforces Round #235 (Div. 2) A. Vanya and Cards
- codeforces 401A - Vanya and Cards
- codeforces 235 div2 B. Sereja and Contests
- CodeForces 258A Vanya and Cards
- codeforces 355(Div 2)C. Vanya and Label(思维,预处理)
- Codeforces-Round-#356-(Div.-2)-Bear-and-Five-Cards
- CodeForces #308 Div2 E(552E Vanya and Brackets)
- codeforces 677 B Vanya and Food Processor (模拟)
- Codeforces Round #355 (Div. 2)- Vanya and Fence(模拟)
- Codeforces Round #280 (Div. 2)B. Vanya and Lanterns(贪心)
- Codeforces Round #129 (Div. 2) D. Little Elephant and Cards
- Codeforces-492B-Vanya and Lanterns
- [CodeForces] Round #313 Div 2 E / Div 1 C Gerald and Giant Chess 不用容斥的递推组合数学
- codeforces --- Round #250 (Div. 2) A. The Child and Homework
- CodeForces 552A-Vanya and Table【模拟】
- Codeforces 851B && Round #432 Div. 2 B. Arpa and an exam about geometry
- Codeforces 432 Div. 2-D-Arpa and a list of numbers(枚举倍数求GCD)
- codeforces A. Vanya and Cards
- A. Vanya and Cards