博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #311 (Div. 2) A. Ilya and Diplomas 水题
阅读量:6713 次
发布时间:2019-06-25

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

A. Ilya and Diplomas

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/557/problem/A

Description

Soon a school Olympiad in Informatics will be held in Berland, n schoolchildren will participate there.
At a meeting of the jury of the Olympiad it was decided that each of the n participants, depending on the results, will get a diploma of the first, second or third degree. Thus, each student will receive exactly one diploma.
They also decided that there must be given at least min1 and at most max1 diplomas of the first degree, at least min2 and at most max2 diplomas of the second degree, and at least min3 and at most max3 diplomas of the third degree.
After some discussion it was decided to choose from all the options of distributing diplomas satisfying these limitations the one that maximizes the number of participants who receive diplomas of the first degree. Of all these options they select the one which maximizes the number of the participants who receive diplomas of the second degree. If there are multiple of these options, they select the option that maximizes the number of diplomas of the third degree.
Choosing the best option of distributing certificates was entrusted to Ilya, one of the best programmers of Berland. However, he found more important things to do, so it is your task now to choose the best option of distributing of diplomas, based on the described limitations.
It is guaranteed that the described limitations are such that there is a way to choose such an option of distributing diplomas that all n participants of the Olympiad will receive a diploma of some degree.

Input

The first line of the input contains a single integer n (3 ≤ n ≤ 3·106) — the number of schoolchildren who will participate in the Olympiad.

The next line of the input contains two integers min1 and max1 (1 ≤ min1 ≤ max1 ≤ 106) — the minimum and maximum limits on the number of diplomas of the first degree that can be distributed.
The third line of the input contains two integers min2 and max2 (1 ≤ min2 ≤ max2 ≤ 106) — the minimum and maximum limits on the number of diplomas of the second degree that can be distributed.
The next line of the input contains two integers min3 and max3 (1 ≤ min3 ≤ max3 ≤ 106) — the minimum and maximum limits on the number of diplomas of the third degree that can be distributed.
It is guaranteed that min1 + min2 + min3 ≤ n ≤ max1 + max2 + max3.

Output

In the first line of the output print three numbers, showing how many diplomas of the first, second and third degree will be given to students in the optimal variant of distributing diplomas.

The optimal variant of distributing diplomas is the one that maximizes the number of students who receive diplomas of the first degree. Of all the suitable options, the best one is the one which maximizes the number of participants who receive diplomas of the second degree. If there are several of these options, the best one is the one that maximizes the number of diplomas of the third degree.

Sample Input

6

1 5
2 6
3 7

Sample Output

1 2 3

HINT

 

题意

a>b>c,a+b+c=n

告诉你a,b,c的取值范围,让你构造出a,b,c的值

题解:

数学题啦

具体看代码~

代码

 

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
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 test freopen("test.txt","r",stdin)#define maxn 100005#define mod 10007#define eps 1e-9const int inf=0x3f3f3f3f;const ll infll = 0x3f3f3f3f3f3f3f3fLL;inline ll read(){ ll 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 main(){ int n=read(); int a[4],b[4]; for(int i=1;i<=3;i++) a[i]=read(),b[i]=read(); int ans[4]; ans[1]=min(n-a[2]-a[3],b[1]); n-=ans[1]; ans[2]=min(n-a[3],b[2]); ans[3]=n-ans[2]; cout<
<<" "<
<<" "<
<

 

转载地址:http://vohlo.baihongyu.com/

你可能感兴趣的文章
Install IIS from Windows Server 2008 R2
查看>>
Lync Server 2010迁移至Lync Server 2013部署系列 Part7:配置Office Web App 02
查看>>
我的友情链接
查看>>
WAITED TOO LONG FOR A ROW CACHE ENQUEUE LOCK!的分析
查看>>
nginx禁止ip直接访问
查看>>
hadoop常用服务管理命令
查看>>
10.28 rsync工具10.29-10.30 rsync选项10.31 rsync通过ssh同步
查看>>
Fault,Error and Failure
查看>>
Go语言的通道(1)-无缓冲通道
查看>>
spring oauth从请求中获取token
查看>>
6.18docker(一)Compose 模板文件
查看>>
每天学点GDB 9
查看>>
前端静态资源缓存控制策略浅析
查看>>
不同模式打开文件的完全列表
查看>>
Jackson将json字符串转换成泛型List
查看>>
jsp,el表达式
查看>>
【leetcode】1035. Uncrossed Lines
查看>>
为什么要用 /dev/null 2>&1 这样的写法
查看>>
简说设计模式
查看>>
java学习面试精华
查看>>