A. Ilya and Diplomas

原创 2015年07月07日 18:22:49

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

解题说明:此题其实是个选数问题,在保证每个满足每个区间的条件时,让某个区间内的值尽可能大,可以采用贪心来做。


#include<stdio.h>
#include <string.h>

int main()
{
    int n,a1,a2,b1,b2,c1,c2,x,y;
    scanf("%d%d%d%d%d%d%d",&n,&a1,&a2,&b1,&b2,&c1,&c2);
    if(n-b1-c1<=a2)
    {
		x=n-b1-c1;
	}
	else
    {
		x=a2;
	}
	n=n-x;
    printf("%d ",x);
    if(n-c1<=b2)
    {
		y=n-c1;
	}
	else
    {
		y=b2;
	}
	printf("%d %d\n",y,n-y);
    return 0;
}


相关文章推荐

CodeForces - 557A Ilya and Diplomas

Ilya and Diplomas Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64...

Codeforces Round #297 (Div. 2) C.Ilya and Sticks

题意:有一堆木棒,每根木棒有一个长度l,每根木棒可以砍掉1个单位长度变成l - 1,用这些木棒拼成矩形,使得拼成的矩形面积最大,问最多能拼成的矩形面积的总和。 基本思路:由于拼成矩形至少需要两对长...
  • PSU_VJD
  • PSU_VJD
  • 2015年03月27日 03:45
  • 265

Codeforce 313C Ilya and Matrix

C. Ilya and Matrix time limit per test 2 seconds memory limit per test 256 megabytes ...

Codeforces Round #186 (Div. 2) D Ilya and Roads DP 单调优化

刚开始犯2去想肿么建图了。 dp还是很好想: 定义 dp[i][x]  表示从 1 到 i 被覆盖了x个洞需要的最小花费。转移方程很简单, 对于 j >i 的有:dp[j][  x + j...

【Codeforces 754 B Ilya and tic-tac-toe game】

B. Ilya and tic-tac-toe game time limit per test 2 seconds memory limit per test 256 megabytes ...

Codeforces_round297_C. Ilya and Sticks

英文原题 In the evening, after the contest Ilya was bored, and he really felt like maximizing. He rem...

codeforces——313A——Ilya and Bank Account

A. Ilya and Bank Account time limit per test 2 seconds memory limit per test 256 megabytes ...

Codeforces 313D Ilya and Roads【Dp+思维】

D. Ilya and Roads time limit per test 3 seconds memory limit per test 256 megabytes input...

Ilya and Escalator-python

题目Ilya got tired of sports programming, left university and got a job in the subway. He was given th...
  • iboxty
  • iboxty
  • 2016年04月05日 12:59
  • 191

Codeforces 518D Ilya and Escalator【概率dp】

D. Ilya and Escalator time limit per test 2 seconds memory limit per test 256 megabytes i...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:A. Ilya and Diplomas
举报原因:
原因补充:

(最多只允许输入30个字)