题目描述:
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.
输入描述:
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.
输出描述:
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.
测试样例:
样例输入 1
Copy
2 8
4 4
样例输出 1
Copy
3 3
样例输入 2
Copy
1 3
5
样例输出 2
Copy
4
样例输入 3
Copy
2 3
2 3
样例输出 3
Copy
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.
题意
给你n个骰子并告诉你每个骰子最大能摇出几,然后摇这n个骰子使他们点数的和为A,问你每个骰子有几个点是安完全不可能摇出来的
思路
可以枚举每个骰子,并且让每个骰子都输出极限的点数,比如:如果n-1个骰子的点数都是1,那么a[i]这个骰子的点数最大应该是Manx=sum-(n-1),如果Manx<=a[i]就说明这个骰子可以摇出这个最大的点数所以ans+=(a[i]-Manx),因为如果你a[i]小于Manx的话别的骰子的点数是进行不了任何操作了因为1已经是最小了;或者让a[i]这个骰子输出最小那么Minx=A-(sum-a[i]),然后如果Minx>=1,则ans+=Minx-1,因为你输出最小的情况就是A减去别的骰子摇出他们最大值的和,同理如果你比1还小那么别的骰子也不可能比本身最大值大所以是Minx-1;
#include "bits/stdc++.h"
using namespace std;
int main(){
long long n,A;
long long a[200005];
cin>>n>>A;
long long sum=0;
for(int i=1;i<=n;i++){
cin>>a[i];
sum+=a[i];
}
for(int i=1;i<=n;i++){
long long ans=0;
if(i!=1) cout<<" ";
long long x=A-(n-1);
if(x<=a[i]) ans+=a[i]-x;
x = A-(sum-a[i]);
if(x>=1) ans+=x-1;
cout<<ans;
}
return 0;
}