C. Polycarpus' Dice

Time Limit: 1 Sec  Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/534/problem/C

Description

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.

Input

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.

Output

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.

Sample Input

input1
2 8
4 4
input2

2 3
2 3

Sample Output

3 3
 
0 1

HINT

题意

给你n个骰子,然后每个骰子有d[i]面,给你一个a,a表示这n个骰子所扔的点数和

然后问你,每一个骰子有多少个数不能投掷到~

题解:

首先,我设骰子扔的点数为x,那么0<x<=d[i],这个是显然的吧
我们设其他骰子扔到的点数为y,则y+x=a,这个也是显然的

y>=n-1,也就是其他的所有骰子都扔1
y<=sum-num[i],也就是其他所有骰子都扔最大值
那么就出来了三个不等式,然后随便解一下就好啦
对了,注意longlong

代码:

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 200001
#define mod 10007
#define eps 1e-9
//const int inf=0x7fffffff; //无限大
const int inf=0x3f3f3f3f;
/*
inline ll read()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int buf[10];
inline void write(int i) {
int p = 0;if(i == 0) p++;
else while(i) {buf[p++] = i % 10;i /= 10;}
for(int j = p-1; j >=0; j--) putchar('0' + buf[j]);
printf("\n");
}
*/
//************************************************************************************** ll num[maxn];
ll ans[maxn];
int main()
{
ll n,a;
cin>>n>>a;
ll sum=;
for(int i=;i<n;i++)
{
cin>>num[i];
sum+=num[i];
}
for(int i=;i<n;i++)
{
ans[i]=min((a+(ll)-n),num[i])-max((a+num[i]-sum),(ll))+;
ans[i]=num[i]-ans[i];
}
for(int i=;i<n;i++)
cout<<ans[i]<<" ";
}

Codeforces Round #298 (Div. 2) C. Polycarpus' Dice 数学的更多相关文章

  1. Codeforces Round #298 (Div. 2) A、B、C题

    题目链接:Codeforces Round #298 (Div. 2) A. Exam An exam for n students will take place in a long and nar ...

  2. CodeForces Round #298 Div.2

    A. Exam 果然,并没有3分钟秒掉水题的能力,=_=|| n <= 4的时候特判.n >= 5的时候将奇数和偶数分开输出即可保证相邻的两数不处在相邻的位置. #include < ...

  3. Codeforces Round #298 (Div. 2)A B C D

    A. Exam time limit per test 1 second memory limit per test 256 megabytes input standard input output ...

  4. Codeforces Round #298 (Div. 2) E. Berland Local Positioning System 构造

    E. Berland Local Positioning System Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.c ...

  5. Codeforces Round #298 (Div. 2) D. Handshakes 构造

    D. Handshakes Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/534/problem ...

  6. Codeforces Round #298 (Div. 2) B. Covered Path 物理题/暴力枚举

    B. Covered Path Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/534/probl ...

  7. Codeforces Round #298 (Div. 2) A. Exam 构造

    A. Exam Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/534/problem/A Des ...

  8. Codeforces Round #298 (Div. 2) B. Covered Path

    题目大意: 一辆车,每秒内的速度恒定...第I秒到第I+1秒的速度变化不超过D.初始速度为V1,末速度为V2,经过时间t,问最远能走多远. 分析 开始的时候想麻烦了.讨论了各种情况.后来发现每个时刻的 ...

  9. Codeforces Round #298 (Div. 2)--D. Handshakes

    #include <stdio.h> #include <algorithm> #include <set> using namespace std; #defin ...

随机推荐

  1. jmeter,测登录,要不要过滤掉JS,CSS等请求?感觉过滤掉了压出来的数据就不真实?

    首先,我们来明确下你的性能测试目的,你的目的是服务端的性能还是前端的性能.这两用目的所涉及到的测试场景和工具等方法是不一样的.1.我们先来谈谈服务端的性能.一般的web产品,像css, jpeg等这种 ...

  2. redhat6.5文件共享

    以下操作均需要root用户 a端: 固定nfs端口 #vi /etc/sysconfig/nfs 将里面的RQUOTAD_PORT.LOCKD_TCPPORT.LOCKD_UDPPORT.MOUNTD ...

  3. mac 删除垃圾篓中的文件

    1.打开终端输入: sudo rm -rf /Volumes/kaid/.Trashes/ 2.输入本机密码

  4. Linux下实现多播(组播)

    单播只能发送给一个接收方,但是当给多个接收者发送时,不仅仅耗费流量,而且耗费时间,总流量=每个接收者的流量*接受者. 广播方式是发送给所有的主机,广播的坏处是会造成信息污染,大量的信息会占用网络带宽. ...

  5. Python基础:获取平台相关信息

    Windows 10家庭中文版,Python 3.6.4, 本文介绍了使用os.platform.sys三个模块获取Python程序的运行平台相关的信息. os模块:提供 各种各样的操作系统接口 os ...

  6. rsync + inotify 实时同步

    1. 前言 2 台 nginx 需要做集群, 静态文件和php文件都在nginx服务器本地. 有三种方案: (1)NFS (2)Rsync + inotify (3)共享存储服务器 第一种:当 nfs ...

  7. Ibatis.Net 各类的作用说明学习(三)

    Ibatis中,加载.分析配置及映射文件是在创建SqlMapper实例的时候进行的,另外对数据库的操作,也是在SqlMapper实例上调用方法来完成.创建SqlMapper的实例的方式是: ISqlM ...

  8. 关于整型Integer、Int32、Int64、IntPtr、UINT、UInt32、Cardinal、UInt64、UIntPtr、NativeUInt、Pointer、Handle

    知识点1:UIntPtr = NativeUInt = Pointer = Handle 随程序的位数改变而改变.如下: 所以以后再用指针的时候要这样:UintPtr/NativeUInt(实例) = ...

  9. 最近公共祖先(LCA)模板

    以下转自:https://www.cnblogs.com/JVxie/p/4854719.html 首先是最近公共祖先的概念(什么是最近公共祖先?): 在一棵没有环的树上,每个节点肯定有其父亲节点和祖 ...

  10. C#socket编程序(三)

    private void ReceiveData() { bool keepalive = true; Socket s = clientSocket; Byte[] buffer = new Byt ...