Ilya and diplomas (greedy 5)

Source: Internet
Author: User

Description

Soon A School Olympiad in Informatics would be held in Berland, n schoolchildren would participate there.

At a meeting of the jury of the Olympiad it is decided that all of the n participants, depending on the Results, would get a diploma of the first, second or third degree. Thus, each student would receive exactly one diploma.

They also decided that there must being given at least min 1 and a T most Max 1 diplomas of the first degree, at least min 2 and at most Max 2 diplomas of the second degree, and at least min 3 and at most Max 3 diplomas of the third degree.< /sub>

After some discussion it is 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 is 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 is entrusted to Ilya, one of the best programmers of Berland. However, he found more important things to does, so it's your task now-choose the best option of distributing of diploma S, based on the described limitations.

It is guaranteed, that the described limitations was such that there is a-to-choose such an option of distributing DIPL Omas that all n participants of the Olympiad would 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 Scho Olchildren who'll participate in the Olympiad.

The next line of the input contains the integers min1 and max1 (1≤ min 1 ≤ 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 the integers min2 and max2 (1≤ m in2≤ max2≤106)-the minimum and maximum limits on the number of diplomas of the second degree that can is distributed.

The next line of the input contains the integers min3 and Max3 (1≤ min 3 ≤ 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≤ nmax1 + max2 + max3.

Output

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

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

Sample Input

Input
6
1 5
2 6
3 7
Output
Input
10
1 2
1 3
1 5
Output
Input
6
1 3
2 2
2 2
Output
#include <stdio.h>#include<string.h>intMain () {intx,y,n,a[Ten],b[Ten]; scanf ("%d",&N);  for(intI=1; i<=3; i++) {scanf ("%d%d",&a[i],&B[i]); }    if(n-a[2]-a[3]>b[1]) {x=b[1];//first, the minimum value of the second third, with n minus the maximum value;    }    Elsex=n-a[2]-a[3]; N=n-x; if(n-a[3]>b[2]) {y=b[2];//first, the third prize is guaranteed the minimum value, with the remaining number to reduce the second prize maximum;    }    Elsey=n-a[3]; printf ("%d%d%d\n", x,y,n-y); return 0;}

Ilya and diplomas (greedy 5)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.