codeforces round #235 A. Vanya and Cards

69 篇文章 0 订阅
11 篇文章 0 订阅
A. Vanya and Cards
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 exceedx 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 foundn 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 andx (1 ≤ x ≤ 1000) — the maximum absolute value of the number on a card. The second line containsn space-separated integers — the numbers on found cards. It is guaranteed that the numbers do not exceedx 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.


简单模拟(贪心)


意思就是说有很多很多卡片 每张卡片上写有一个整数data( data <= |x|) 现在已经找到n张卡片 而且知道上面的数字 问最少再找多少张卡片才能使得总和为0

直接贪心就好了 从最大的找 然后一直找到总和为0 (其实直接求整 然后求模判断加一就好了)


最近总是不在状态啊  这题想了一会 但是写了很久 交了三次WA 发现自己想多了 想到 只有单一卡片的问题了 而且写得特别麻烦加了hash 但是每次都wa in test3

最后发现只是个简单的贪心 果断有时候不能想太多。。。%>_<%


ac代码

http://paste.ubuntu.com/7069064/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值