CF401A.Vanya and Cards

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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.

瓦尼亚喜欢玩游戏。他甚至有一套专门用来游戏的卡片。每张卡片上都有一个整数,该整数可以为正、为负,甚至可以为零。唯一的限制是:每张卡片上的数字的绝对值不超过 xx。

娜塔莎不喜欢瓦尼亚花很长时间玩游戏,因此她藏起了他所有的卡片。瓦尼亚感到难过,开始寻找这些卡片,但只找到了其中的 nn 张。瓦尼亚热爱“平衡”,因此他希望所有已找到卡片上的数字之和为零。另一方面,他寻找卡片已经非常疲惫了。请帮助这个男孩:他至少还需要再找到多少张卡片,才能使所有卡片(包括原先找到的 nn 张)上的数字之和等于零?

你可以假设:最初瓦尼亚拥有无穷多张卡片,且对每个从 −x-x 到 xx 的整数,都存在无穷多张标有该整数的卡片。

输入格式

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.

第一行包含两个整数:nn(1≤n≤10001 \leq n \leq 1000)—— 找到的卡片数量,以及 xx(1≤x≤10001 \leq x \leq 1000)—— 卡片上数字的最大绝对值。
第二行包含 nn 个用空格分隔的整数——找到的卡片上的数字。题目保证这些数字的绝对值均不超过 xx。

输出格式

Print a single number — the answer to the problem.

输出一个数字——该问题的答案。

输入输出样例

  • 输入#1

    3 2
    -1 1 2

    输出#1

    1
  • 输入#2

    2 3
    -2 -2

    输出#2

    2

说明/提示

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.

在第一个样例中,万尼亚需要找到一张编号为 −2-2 的卡片。

在第二个样例中,万尼亚需要找到两张编号为 22 的卡片。他无法找到一张满足要求的卡片,因为丢失的卡片上的数字的绝对值不超过 33。

输入解题思路,AI测评打分。不知道怎么写?

首页