博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CF Polycarpus' Dice (数学)
阅读量:7071 次
发布时间:2019-06-28

本文共 2180 字,大约阅读时间需要 7 分钟。

Polycarpus' Dice
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 test(s)
input
2 8 4 4
output
3 3
input
1 3 5
output
4
input
2 3 2 3
output
0 1 当前骰子最小值 + 剩余筛子最大值 >= A 当前骰子最大值 + 剩余筛子最小值 <= A
#include 
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;int main(void){ int n; int s[200005]; long long A; long long sum = 0; long long ans = 0; cin >> n >> A; for(int i = 0;i < n;i ++) { cin >> s[i]; sum += s[i]; } for(int i = 0;i < n;i ++) { long long m_min = A - sum + s[i]; long long m_max = A - (n - 1); if(m_max > s[i]) m_max = s[i]; ans = s[i] - m_max + (m_min - 1 > 0 ? m_min - 1: 0); cout << ans; if(i != n - 1) cout << ' '; } cout << endl; return 0;}

 

转载于:https://www.cnblogs.com/xz816111/p/4438962.html

你可能感兴趣的文章
我的友情链接
查看>>
openstack概述
查看>>
How To Detect Which Element Was Clicked, Using jQuery
查看>>
javascript & jQuery
查看>>
DW快速去除tppabs冗余代码
查看>>
Java8新特性之:新的日期和时间API
查看>>
如何才能从程序员成长为实战型架构师?必掌握这7大实战技能经验
查看>>
rabbitMQ集群的搭建和维护第二篇---利用python程序完成mq的消息收发和实时监控
查看>>
网众设置开机重启服务的命令,才可连接BOOT服务器
查看>>
RHEL6.3 DNS配置详解一 DNS相关概念理解及配置基础
查看>>
Windows环境 和 Linux环境下搭建Qt开发环境
查看>>
简述synchronized和java.util.concurrent.locks.Lock的异同
查看>>
在win2008r2下开启ntp服务
查看>>
我的友情链接
查看>>
SpringMVC源码解析(三)——HandlerAdapter
查看>>
Python执行系统命令的方法
查看>>
动态加载远程Jar的实现方式
查看>>
无线***笔记(一)-《***WPA-PSK加密无线网络》
查看>>
MyEclipse10.1集成SVN
查看>>
Sitemesh和Struts2结合时Filter的配制顺序
查看>>