A9779 | Polycarpus' Dice
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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$ .
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$ .
输入格式
The first line contains two integers $n,A$ ( $1<=n<=2·10^{5},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}<=10^{6}$ ), where $d_{i}$ is the maximum value that the $i$ -th dice can show.
The second line contains $n$ integers $d_{1},d_{2},...,d_{n}$ ( $1<=d_{i}<=10^{6}$ ), where $d_{i}$ is the maximum value that the $i$ -th dice can show.
输出格式
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.
输入输出样例
输入 #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.
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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted