题目:
http://codeforces.com/contest/534/problem/C
题意:
n个筛子,s为n个筛子的和.给出n个数为每个筛子的最大点数. 求出每个筛子有多少个数是一定不能取的.
思路:
取极限的方法.
每个筛子不能取的点数分别是: 1)当其他筛子取1,此筛子点数大于 s+1-n. 2)当其他筛子取最大值的时候,此筛子小于 s - (sum-a[i]).
AC.
#include <iostream>
#include <cstdio>
using namespace std;
const int maxn = 2e5+5;
int a[maxn];
int main()
{
//freopen("in", "r", stdin);
int n;
long long s;
while(~scanf("%d %I64d", &n, &s)) {
long long res = 0;
for(int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
res += a[i];
}
if(n == 1) {
printf("%d\n", a[0]-1);
}
else {
int ans = 0;
long long y = 0;
for(int i = 0; i < n; ++i) {
ans = 0;
y = s - n + 1;
if(a[i] > y) {
ans += (a[i] - y);
}
y = s - (res - a[i]);
if(y > 0) {
ans += (y-1);
}
if(i != n-1) printf("%d ", ans);
else printf("%d\n", ans);
}
}
}
return 0;
}