Ilya and Diplomas (贪心5)

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

Input

61 52 63 7

Output

1 2 3 

Input

101 21 31 5

Output

2 3 5 

Input

61 32 22 2

Output

2 2 2 
#include <stdio.h>
#include <string.h>
int main()
{
    int x,y,n,a[10],b[10];
    scanf("%d",&n);
    for(int i=1;i<=3;i++)
    {
        scanf("%d%d",&a[i],&b[i]);
    }
    if(n-a[2]-a[3]>b[1])
    {
        x=b[1];//先保证二三等奖最小值,用n减得一等奖最大值;
    }
    else
        x=n-a[2]-a[3];
    n=n-x;
    if(n-a[3]>b[2])
    {
        y=b[2];//先保证三等奖最小值,用剩余的数减得二等奖最大值;
    }
    else
        y=n-a[3];
    printf("%d %d %d\n",x,y,n-y);
    return 0;
}
时间: 2024-10-09 07:54:48

Ilya and Diplomas (贪心5)的相关文章

A. Ilya and Diplomas 贪心小题

A. Ilya and Diplomas 题目抽象:min1<=a<=max1,   min2 <= b <= max2, min3 <= c <= max3;   a+b+c = n. min1 +min2 + min3 <= n <= max1 + max2 + max3; 在满足上面的条件下,第一比较规则a尽可能大,第二比较规则b尽可能大.求出a,b,c; 分析: 贪心即可.分两类, a能否取到最大值,   a取到最大值的话,b能否取到最大值.  见代

Codeforces Round #311 (Div. 2)A Ilya and Diplomas

[比赛链接]click here~~ [题目大意] n个人,获取一到三等文凭,每门文凭有大小范围,求最后文凭各颁发多少 [解题思路]直接枚举了, 看完题,赶紧写了一发代码,发现居然错过注册时间,系统提示不能提交代码,真是醉了~~,以后还是得提前注册: A题,比较简单: 代码: #include <iostream> #include <bits/stdc++.h> using namespace std; int main() { int n,m; int a1,a2; int b

Codeforces 557A Ilya and Diplomas 区间选数

题意:给出3个区间 [L1,R1],[L2,R2],[L3,R3] 和正整数n,要求在3个区间内各选一个正整数,使得选出来的数之和为n.如果有多种选法,取从第一个区间内选出的数最大的选法.如果仍有多种选法,取从第二个区间中选出的数最大的选法,如果仍有多种选法,取从第三个区间内选出的数最大的选法.题目保证至少存在一种选法. 水题.要使第一个区间内选出的数尽量大,意思就是尽量让后两个区间选出的数尽量小,最小可以取到区间下界.于是第一个区间选的数ans1 = min(R1,n - L2 - L3).同

2017-4-25-Train:Codeforces Round #311 (Div. 2)

A. Ilya and Diplomas(贪心) 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 g

Codeforces Round #311 (Div. 2) A,B,C,D,E

A. Ilya and Diplomas 思路:水题了, 随随便便枚举一下,分情况讨论一下就OK了. code: #include <stdio.h> #include <stdlib.h> #include <string.h> #include <algorithm> #include <iostream> #include <cstring> #include <cmath> #define inf 1000000

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

题目传送门 1 /* 2 题意:给n个棍子,组成的矩形面积和最大,每根棍子可以-1 3 贪心:排序后,相邻的进行比较,若可以读入x[p++],然后两两相乘相加就可以了 4 */ 5 #include <cstdio> 6 #include <algorithm> 7 #include <cstring> 8 #include <cmath> 9 using namespace std; 10 11 typedef long long ll; 12 13 co

ural 1431. Diplomas

1431. Diplomas Time limit: 1.0 secondMemory limit: 64 MB It might be interesting for you to learn that there are students who take part in various contests instead of studying. Sometimes such students are even awarded diplomas for winning these conte

URAL 2000. Grand Theft Array V(贪心啊)

题目链接:http://acm.timus.ru/problem.aspx?space=1&num=2000 2000. Grand Theft Array V Time limit: 0.5 second Memory limit: 64 MB A long anticipated game called Grand Theft Array V is about to appear in shops! What, haven't you heard of it? Then we must te

【uva 1615】Highway(算法效率--贪心 区间选点问题)

题意:给定平面上N个点和一个值D,要求在x轴上选出尽量少的点,使得对于给定的每个店,都有一个选出的点离它的欧几里德距离不超过D. 解法:先把问题转换成模型,把对平面的点满足条件的点在x轴的直线上可得到一个个区间,这样就是选最小的点覆盖所有的区间的问题了.我之前的一篇博文有较详细的解释:关于贪心算法的经典问题(算法效率 or 动态规划).代码实现我先空着.挖坑~