A. Ilya and Diplomas( Codeforces Round #311 (Div. 2) )
1 second
256 megabytes
standard input
standard output
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 mostmax2 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 nparticipants
of the Olympiad will receive a diploma of some degree.
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.
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.
6
1 5
2 6
3 7
1 2 3
10
1 2
1 3
1 5
2 3 5
6
1 3
2 2
2 2
2 2 2
题意:给出3个区间 [L1,R1],[L2,R2],[L3,R3] 和正整数n,要求在3个区间内各选一个正整数。使得选出来的数之和为n。假设有多种选法,取从第一个区间内选出的
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<stdlib.h> using namespace std; int n;
struct node
{
int minn;
int maxx;
}q[5]; int main()
{
while(scanf("%d",&n)!=EOF)
{
for(int i=1;i<=3;i++)
{
scanf("%d%d",&q[i].minn,&q[i].maxx);
}
int a[5];
int sum = n;
memset(a,0,sizeof(a));
for(int i=1;i<=3;i++)
{
a[i] = q[i].minn;
sum -= a[i];
}
for(int i=1;i<=3;i++)
{
int num = q[i].maxx - q[i].minn;
if(sum>=num)
{
a[i] += num;
sum -= num;
}
else
{
a[i] += sum;
break;
}
}
printf("%d %d %d\n",a[1],a[2],a[3]);
}
return 0;
}
A. Ilya and Diplomas( Codeforces Round #311 (Div. 2) )的更多相关文章
- 【CodeForces】841D. Leha and another game about graph(Codeforces Round #429 (Div. 2))
[题意]给定n个点和m条无向边(有重边无自环),每个点有权值di=-1,0,1,要求仅保留一些边使得所有点i满足:di=-1或degree%2=di,输出任意方案. [算法]数学+搜索 [题解] 最关 ...
- C. Arthur and Table(Codeforces Round #311 (Div. 2) 贪心)
C. Arthur and Table time limit per test 1 second memory limit per test 256 megabytes input standard ...
- B. Ohana Cleans Up(Codeforces Round #309 (Div. 2))
B. Ohana Cleans Up Ohana Matsumae is trying to clean a room, which is divided up into an n by n gr ...
- B. The Number of Products(Codeforces Round #585 (Div. 2))
本题地址: https://codeforces.com/contest/1215/problem/B 本场比赛A题题解:https://www.cnblogs.com/liyexin/p/11535 ...
- 【CodeForces】841C. Leha and Function(Codeforces Round #429 (Div. 2))
[题意]定义函数F(n,k)为1~n的集合中选择k个数字,其中最小数字的期望. 给定两个数字集A,B,A中任意数字>=B中任意数字,要求重组A使得对于i=1~n,sigma(F(Ai,Bi))最 ...
- D. Zero Quantity Maximization ( Codeforces Round #544 (Div. 3) )
题目链接 参考题解 题意: 给你 整形数组a 和 整形数组b ,要你c[i] = d * a[i] + b[i], 求 在c[i]=0的时候 相同的d的数量 最多能有几个. 思路: 1. 首先打开 ...
- Vus the Cossack and Strings(Codeforces Round #571 (Div. 2))(大佬的位运算实在是太强了!)
C. Vus the Cossack and Strings Vus the Cossack has two binary strings, that is, strings that consist ...
- CodeForces 360E Levko and Game(Codeforces Round #210 (Div. 1))
题意:有一些无向边m条权值是给定的k条权值在[l,r]区间可以由你来定,一个点s1 出发一个从s2出发 问s1 出发的能不能先打到f 思路:最短路. 首先检测能不能赢 在更新的时候 如果对于一条边 ...
- 贪心+构造( Codeforces Round #344 (Div. 2))
题目:Report 题意:有两种操作: 1)t = 1,前r个数字按升序排列: 2)t = 2,前r个数字按降序排列: 求执行m次操作后的排列顺序. #include <iostream&g ...
随机推荐
- HDU 4312 Contest 2
题目要求两点间的最大值作为距离即: 即是切比雪夫距离.而切比雪夫距离与曼哈顿距离的转换却很巧妙. 把平面坐标所有点绕原点逆向旋转45度后,所得点的曼哈顿距离之和除以√2,即是切雪比夫距离.旋转点的公式 ...
- GNU Linux中的SO_RCVLOWAT和SO_SNDLOWAT说明
/********************************************************************* * Author : Samson * Date ...
- @dynamic与@synthesize的差别
如今非常多时候我们都已经不再使用@synthesizekeyword了,可是须要了解当中的原理: 一.@dynamic与@synthesize的差别 @property有两个相应的词.一个是@synt ...
- CxImage动态加载图片(判断图片文件类型)
1.打开一张图可以通过创建一个新的CxImage对象来完成,通过构造函数来打开一张图CxImage::CxImage(const char * filename, DWORD imagetype)其中 ...
- Java8 方法引用与构造器引用,数组引用
package java_8; import org.junit.Test; import java.io.PrintStream; import java.util.Comparator; impo ...
- BZOJ 3569 询问删除指定的k条边后图是否连通 线性基
思路: 这题思路好鬼畜啊-- 绝对是神思路 //By SiriusRen #include <cstdio> #include <algorithm> using namesp ...
- URAL 1297 后缀数组+线段树
思路: 论文题--*n 倒过来接上 分奇偶讨论 求LCP 搞棵线段树即可 //By SiriusRen #include <cstdio> #include <cstring> ...
- Ubuntu14.04下Mongodb(在线安装方式|apt-get)安装部署步骤(图文详解)(博主推荐)
不多说,直接上干货! 本博文介绍了MongoDB,并详细指引读者在Ubuntu下MongoDB的安装和使用.本教程在Ubuntu14.04下测试通过. 一.MongoDB介绍 MongoDB 是一个是 ...
- sqlserver如何给某一用户分配只能查看某一视图的权限
exec sp_addrole 'guestview' --GRANT SELECT ON veiw TO [guestview]; GRANT SELECT ON CustomerInfo TO ...
- 洛谷P1339 [USACO09OCT]热浪Heat Wave(最短路)
题目描述 The good folks in Texas are having a heatwave this summer. Their Texas Longhorn cows make for g ...