1 second
256 megabytes
standard input
standard output
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.
2 8
4 4
3 3
1 3
5
4
2 3
2 3
0 1 当前骰子最小值 + 剩余筛子最大值 >= A
当前骰子最大值 + 剩余筛子最小值 <= A
#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cctype>
#include <queue>
#include <map>
using namespace std; int main(void)
{
int n;
int s[];
long long A;
long long sum = ;
long long ans = ; cin >> n >> A;
for(int i = ;i < n;i ++)
{
cin >> s[i];
sum += s[i];
}
for(int i = ;i < n;i ++)
{
long long m_min = A - sum + s[i];
long long m_max = A - (n - );
if(m_max > s[i])
m_max = s[i];
ans = s[i] - m_max + (m_min - > ? m_min - : );
cout << ans;
if(i != n - )
cout << ' ';
}
cout << endl; return ;
}