Codeforces534C:Polycarpus' Dice
来源:互联网 发布:网络购物合同纠纷举证 编辑:程序博客网 时间:2024/06/07 09:29
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 84 4
3 3
1 35
4
2 32 3
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,A,一共有n个色子,他们向上的点数和为A,然后给出n个数,分别代表每个色子最大的掷出点数,要求出每个色子有几个值是不可能掷出的
思路:对于一个色子,我们先求出其他色子能这出的最大值与最小值之和,那么我们就能得到这个色子所可能掷出的区间,然后就得到了不能掷出的个数
#include <iostream>#include <stdio.h>#include <string.h>#include <stack>#include <queue>#include <map>#include <set>#include <vector>#include <math.h>#include <algorithm>using namespace std;#define ls 2*i#define rs 2*i+1#define up(i,x,y) for(i=x;i<=y;i++)#define down(i,x,y) for(i=x;i>=y;i--)#define mem(a,x) memset(a,x,sizeof(a))#define w(a) while(a)#define LL long longconst double pi = acos(-1.0);#define Len 1000006#define mod 1000000007const int INF = 0x3f3f3f3f;LL n,sum,a[300000],cnt;int main(){ LL i,j,ss; w(~scanf("%I64d%I64d",&n,&sum)) { ss = 0; up(i,1,n) { scanf("%I64d",&a[i]); ss+=a[i]; } up(i,1,n) { cnt = 0; LL minn = n-1,maxn = ss-a[i]; LL l = sum-maxn,r = sum-minn; if(l>0) cnt += l-1; if(r<=a[i]) cnt+=(a[i]-r); if(i!=1) printf(" "); printf("%I64d",cnt); } printf("\n"); } return 0;}
- Codeforces534C:Polycarpus' Dice
- cf. Polycarpus' Dice
- Polycarpus' Dice CodeForces
- CodeForces 534C - Polycarpus' Dice
- CodeForces 534C Polycarpus' Dice
- #298 (div.2) C. Polycarpus' Dice
- Code Forces 298 C Polycarpus' Dice
- CodeForces 534C Polycarpus' Dice 【数学】
- Codeforces 534C Polycarpus' Dice(思路)
- Codeforces 534 C. Polycarpus' Dice【思维】
- Codeforces 534C Polycarpus' Dice(数学,公式推导)
- 534C. Polycarpus' Dice(Codeforces Round #298(div2))
- Codeforces Round #298 (Div. 2) C. Polycarpus' Dice(数学)
- CodeForce 534C Polycarpus' Dice (数学推理)
- Codeforces Round #298 (Div. 2) C Polycarpus' Dice
- Codeforces Round #298 (Div. 2) -- Polycarpus' Dice (数学推理)
- Codeforces Round #298 (Div. 2) C. Polycarpus' Dice(思路)
- CodeForce 534C Polycarpus' Dice (数学推理)
- 黑马程序员_日记58_HashMap自定义对象存取练习
- linux常用命令整理之四
- AsyncTask(异步任务)
- 面试求职之准备篇
- linux常用命令整理之五
- Codeforces534C:Polycarpus' Dice
- 斐波那契数列的几种计算机解法
- linux常用命令整理之六
- ERROR 1130 (HY000): Host '192.168.225.128' is not allowed to connect to this MySQL server
- 字符串压缩
- swift app入门 学习总结
- linux常用命令整理之七
- HTML5 SVG 特效示例
- CSU 1562 — Fun House