SDKD 2016 Summer Single Contest #12 .G
2016-07-25 21:02
411 查看
Polycarp has n dice d1, d2, …, dn. The i-th dice shows numbers from 1 to di. 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 d1, d2, …, dn. 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.
Input
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 = d1 + d2 + … + dn.
The second line contains n integers d1, d2, …, dn (1 ≤ di ≤ 106), where di is the maximum value that the i-th dice can show.
Output
Print n integers b1, b2, …, bn, where bi is the number of values for which it is guaranteed that the i-th dice couldn’t show them.
Sample Input
Input
2 8
4 4
Output
3 3
Input
1 3
5
Output
4
Input
2 3
2 3
Output
0 1
Hint
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.
题目:
这就是一数学题,还要注意 longlong
这题就是 要求一个范围 即 每个dn 可以 取得范围 ,其他的 就是不能取得。
现在求范围:
除了这个数 其他的数 取 最小 1 那么这个数就要取得最大 ,
除了这个数 其他的数 取 最大 sum - dn 那么这个数就取最小
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.
Input
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 = d1 + d2 + … + dn.
The second line contains n integers d1, d2, …, dn (1 ≤ di ≤ 106), where di is the maximum value that the i-th dice can show.
Output
Print n integers b1, b2, …, bn, where bi is the number of values for which it is guaranteed that the i-th dice couldn’t show them.
Sample Input
Input
2 8
4 4
Output
3 3
Input
1 3
5
Output
4
Input
2 3
2 3
Output
0 1
Hint
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.
题目:
这就是一数学题,还要注意 longlong
这题就是 要求一个范围 即 每个dn 可以 取得范围 ,其他的 就是不能取得。
现在求范围:
除了这个数 其他的数 取 最小 1 那么这个数就要取得最大 ,
除了这个数 其他的数 取 最大 sum - dn 那么这个数就取最小
#include <iostream> #include <string> #include <cstring> #include <cstdio> #include <algorithm> #include <cmath> using namespace std; const int maxn = 200000 + 100; long long n, A; long long sum = 0; long long d[maxn]; int main() { cin >> n >> A; for(int i = 0; i < n; i++) { cin >> d[i]; sum += d[i]; } for(int i = 0; i < n; i++) { int mmax = min(A - (n-1), d[i]); int mmin = max(1LL, A - (sum - d[i])); if(i != 0) printf(" "); printf("%d", mmin-1 + d[i] - mmax); } return 0; }
相关文章推荐
- 【HDU 2602】Bone Collector(01背包)
- 文本居中
- CodeForces 540A Combination Lock
- 2016/07/25 初识java
- 版本管理工具(待续)
- session入mysql
- javascript正则表达式
- DOM、SAX、JDOM、DOM4J以及PULL在XML文件解析中的工作原理以及优缺点对比
- DOM、SAX、JDOM、DOM4J以及PULL在XML文件解析中的工作原理以及优缺点对比
- 最美公式:世上最伟大的十个公式
- 几乎零配置产生Nuget包的库:White Tie
- [LeetCode练习题-C语言]203. Remove Linked List Elements
- Linux运维学习历程-第二天-虚拟机的配置
- 清除confluent 在zookeeper中的数据
- Android socket通信 readline方法阻塞
- 异常捕获
- Ubuntu下安装Python
- 开始语
- 330. Patching Array
- 卷积神经网络问题总结