Codeforces Round 311 (Div. 2)
A
Ilya and Diplomas
Codeforces
1100
原题
←B →
翻译中…

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 $*min*_{1}$ and at 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.

翻译中…

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·10^{6}$) — the number of schoolchildren who will participate in the Olympiad.

翻译中…

The next line of the input contains two integers $*min*_{1}$ and $*max*_{1}$ ($1 ≤ *min*_{1} ≤ *max*_{1} ≤ 10^{6}$) — 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 $*min*_{2}$ and $*max*_{2}$ ($1 ≤ *min*_{2} ≤ *max*_{2} ≤ 10^{6}$) — 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 $*min*_{3}$ and $*max*_{3}$ ($1 ≤ *min*_{3} ≤ *max*_{3} ≤ 10^{6}$) — the minimum and maximum limits on the number of diplomas of the third degree that can be distributed.

翻译中…

It is guaranteed that $*min*_{1} + *min*_{2} + *min*_{3} ≤ *n* ≤ *max*_{1} + *max*_{2} + *max*_{3}$.

翻译中…

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.

翻译中…

样例

Input #1
6
1 5
2 6
3 7
Output #1
1 2 3
InputCopy OutputCopy
Input #2
10
1 2
1 3
1 5
Output #2
2 3 5
InputCopy OutputCopy
Input #3
6
1 3
2 2
2 2
Output #3
2 2 2
InputCopy OutputCopy
题目信息
题号
557A
时间限制
1 s
内存限制
256 MB
标签
贪心
模拟
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。