A. Ilya and Diplomas
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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.

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 test(s)
input
6
1 5
2 6
3 7
output
1 2 3
input
10
1 2
1 3
1 5
output
2 3 5
input
6
1 3
2 2
2 2
output
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) )的更多相关文章

  1. 【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,输出任意方案. [算法]数学+搜索 [题解] 最关 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. 【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))最 ...

  6. D. Zero Quantity Maximization ( Codeforces Round #544 (Div. 3) )

    题目链接 参考题解 题意: 给你 整形数组a 和 整形数组b ,要你c[i] = d * a[i] + b[i], 求  在c[i]=0的时候  相同的d的数量 最多能有几个. 思路: 1. 首先打开 ...

  7. 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 ...

  8. CodeForces 360E Levko and Game(Codeforces Round #210 (Div. 1))

    题意:有一些无向边m条权值是给定的k条权值在[l,r]区间可以由你来定,一个点s1 出发一个从s2出发  问s1 出发的能不能先打到f 思路:最短路. 首先检测能不能赢 在更新的时候  如果对于一条边 ...

  9. 贪心+构造( Codeforces Round #344 (Div. 2))

    题目:Report 题意:有两种操作: 1)t = 1,前r个数字按升序排列:   2)t = 2,前r个数字按降序排列: 求执行m次操作后的排列顺序. #include <iostream&g ...

随机推荐

  1. 【【henuacm2016级暑期训练】动态规划专题 F】Physics Practical

    [链接] 我是链接,点我呀:) [题意] 给你n个数字 让你删掉最小的数字 使得: 剩余的数字中 "最大的数字"小于等于"最小的数字*2" [题解] 把数据从小 ...

  2. ASP.NET-关于Global.asax的作用

    这个文件相当于一个应用程序量级的 全局文件,比如你想写一个变量在项目中的所有文件中都能读取是就写在这里面 Application["name"] = "zhangran& ...

  3. UVALive - 2031 Dance Dance Revolution 三维dp

    题目大意:有一个胖子在玩跳舞机.刚開始的位置在(0,0).跳舞机有四个方向键,上左下右分别相应1,2,3,4.如今有下面规则 1.假设从0位置移动到随意四个位置,消耗能量2 2.假设从非0位置跳到相邻 ...

  4. Android在程序中浏览网页

    本文是自己学习所做笔记,欢迎转载.但请注明出处:http://blog.csdn.net/jesson20121020 有时须要在程序中浏览一些网页.当然了能够通过调用系统的浏览器来打开浏览.可是大多 ...

  5. Android 自己定义RecyclerView 实现真正的Gallery效果

    转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/38173061 .本文出自:[张鸿洋的博客] 上一篇博客我使用自己定义Horizo ...

  6. 【跟我一步一步学Struts2】——拦截器

    前言 前面提到过拦截器.而且说拦截器仅仅能拦截Action.这里拦截器的调用体现了责任链模式.为什么说体现了责任链模式呢? 以下的一段话说的非常明确: Struts2将整个运行划分成若干同样类型的元素 ...

  7. 用exp命令按用户导出的DMP文件缺少表,某些表是空表

    1.用以下这句查找空表并生成执行命令 select 'alter table '||table_name||' allocate extent;' from user_tables where num ...

  8. 解决linux ping: unknown host www.baidu.com

    如果ping域名的时候出现ping:unknown host  xxx.xxx 但是ping IP地址的时候可以通的话 可知是dns服务器没有配置好, 查看一下配置文件/etc/resolv.conf ...

  9. sicily 1137 河床 (二分分治)

    <计算机算法设计与分析>啃书中... 有点看不进书,就来刷个水题吧,刚开始看错题了还. 注意:是所有测量点相差均不大于di而不是相邻两点... //1137.河床 #include < ...

  10. 微信重排版 URL

    http://qbview.url.cn/getResourceInfo?appid=62&url=https%3A%2F%2Fcodepen.io%2Fbenjamminf%2Ffull%2 ...