您的位置:首页 > 其它

Codeforces Round #298 (Div. 2) C. Polycarpus' Dice(思路)

2016-07-27 18:58 351 查看
题目地址:http://codeforces.com/problemset/problem/534/C

思路:对于当前色子,求出其他色子所能掷出的最小值之和与最大值之和。当其他色子取最小值时,该色子取最大值A-(n-1),大于该值均不可能;当其它色子取最大值,该色子取最小值A-sum+a[i],小于该值均不可能。则由不可能区间可以求出不可能掷出的数字个数。

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long  LL;
LL sum,A;
int n,a[200050];
int main()
{
scanf("%d%I64d",&n,&A);
for(int i=1; i<=n; i++)
{
scanf("%d",&a[i]);
sum+=a[i];
}
for(int i=1; i<=n; i++)
{
LL ans=0;
LL tmp=A-(n-1);
ans+=a[i]-tmp>0?a[i]-tmp:0;
tmp=A-sum+a[i];
ans+=tmp-1>0?tmp-1:0;
if(i==1) printf("%I64d",ans);
else printf(" %I64d\n",ans);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: