注意多组数据分别输出时,一般都是互不干扰的
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 200010;
int n;
LL S;
int a[N];
int get(LL a, LL b, LL c, LL d)//区间函数,找到区间相同的的元素个数,多次调用时考虑函数解决问题)
{
return min(b, d) - max(a, c) + 1;//四个端点
}
int main()
{
scanf("%d%lld", &n, &S);//数据大于10w以上时尽量用scanf输入printf输出,减少时间损耗
LL sum = 0;
for (int i = 1; i <= n; i ++ )
{
scanf("%d", &a[i]);
sum += a[i];//前缀和
}
for (int i = 1; i <= n; i ++ )
printf("%d ", a[i] - get(1, a[i], S - (sum - a[i]), S - (n - 1)));
// cout << (double)clock() / CLOCKS_PER_SEC << "s";
return 0;
}