CF534C.Polycarpus' Dice

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Polycarp has n dice _d_1, _d_2, ..., d__n. The i-th dice shows numbers from 1 to d__i. Polycarp rolled all the dice and the sum of numbers they showed is A. Agrippina didn't see which dice showed what number, she knows only the sum A and the values _d_1, _d_2, ..., d__n. However, she finds it enough to make a series of statements of the following type: dice i couldn't show number r. For example, if Polycarp had two six-faced dice and the total sum is A = 11, then Agrippina can state that each of the two dice couldn't show a value less than five (otherwise, the remaining dice must have a value of at least seven, which is impossible).

For each dice find the number of values for which it can be guaranteed that the dice couldn't show these values if the sum of the shown values is A.

Polycarp 有 nn 枚骰子 d1,d2,…,dnd_1, d_2, \dots, d_n。第 ii 枚骰子能显示的数字范围是 11 到 did_i。Polycarp 投掷了所有骰子,它们显示的数字之和为 AA。Agrippina 并未看到每枚骰子具体显示的数字,她只知道总和 AA 以及各骰子的面数 d1,d2,…,dnd_1, d_2, \dots, d_n。然而,仅凭这些信息,她便能够做出一系列如下形式的断言:“第 ii 枚骰子不可能显示数字 rr”。例如,若 Polycarp 有两枚六面骰子,且总和 A=11A = 11,则 Agrippina 可以断言:这两枚骰子均不可能显示小于 55 的数(否则,另一枚骰子需显示至少 77,这是不可能的)。

对每枚骰子,求出在总和为 AA 的前提下,可以确定该骰子绝不可能显示的数值个数。

输入格式

The first line contains two integers n, A (1 ≤ n ≤ 2·105, n ≤ A ≤ s) — the number of dice and the sum of shown values where s = _d_1 + _d_2 + ... + d__n.

The second line contains n integers _d_1, _d_2, ..., d__n (1 ≤ d__i ≤ 106), where d__i is the maximum value that the i-th dice can show.

第一行包含两个整数 nn 和 AA(1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5,n≤A≤sn \leq A \leq s),其中 nn 表示骰子的数量,AA 表示显示值的总和,而 s=d1+d2+⋯+dns = d_1 + d_2 + \dots + d_n。

第二行包含 nn 个整数 d1,d2,…,dnd_1, d_2, \dots, d_n(1≤di≤1061 \leq d_i \leq 10^6),其中 did_i 表示第 ii 个骰子所能显示的最大值。

输出格式

Print n integers _b_1, _b_2, ..., b__n, where b__i is the number of values for which it is guaranteed that the i-th dice couldn't show them.

输出 $ n $ 个整数 $ b_1, b_2, \dots, b_n $,其中 $ b_i $ 表示第 $ i $ 个骰子不可能显示的数值的个数(即:可以保证第 $ i $ 个骰子不会显示的数值的个数)。

输入输出样例

  • 输入#1

    2 8
    4 4

    输出#1

    3 3
  • 输入#2

    1 3
    5

    输出#2

    4
  • 输入#3

    2 3
    2 3

    输出#3

    0 1

说明/提示

In the first sample from the statement A equal to 8 could be obtained in the only case when both the first and the second dice show 4. Correspondingly, both dice couldn't show values 1, 2 or 3.

In the second sample from the statement A equal to 3 could be obtained when the single dice shows 3. Correspondingly, it couldn't show 1, 2, 4 or 5.

In the third sample from the statement A equal to 3 could be obtained when one dice shows 1 and the other dice shows 2. That's why the first dice doesn't have any values it couldn't show and the second dice couldn't show 3.

在题目给出的第一个样例中,当且仅当两个骰子均显示 4 时,可得到 A=8A = 8。因此,两个骰子均不能显示 1、2 或 3。

在题目给出的第二个样例中,当唯一的骰子显示 3 时,可得到 A=3A = 3。因此,该骰子不能显示 1、2、4 或 5。

在题目给出的第三个样例中,当一个骰子显示 1、另一个骰子显示 2 时,可得到 A=3A = 3。因此,第一个骰子没有任何不能显示的值,而第二个骰子不能显示 3。

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

首页