302873: CF557A. Ilya and Diplomas

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

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

输入输出格式

输入格式


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

输出格式


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.

输入输出样例

输入样例 #1

6
1 5
2 6
3 7

输出样例 #1

1 2 3 

输入样例 #2

10
1 2
1 3
1 5

输出样例 #2

2 3 5 

输入样例 #3

6
1 3
2 2
2 2

输出样例 #3

2 2 2 

Input

题意翻译

#### 题目描述 不久将在 Berland 举行一场信息奥林匹克竞赛,将有 $n$ 名学生参加。 在奥赛评委会议上,决定根据比赛成绩,为每个参赛者颁发一、二或三等证书。因此,每个学生将获得且只能获得一个证书。 他们还决定一定要颁发至少 $\min_1$ 和至多 $\max_1$ 个一等证书,至少 $\min_2$ 和至多 $\max_2$ 个二等证书,以及至少 $\min_3$ 和至多 $\max_3$ 个三等证书。 经过一番讨论,决定从满足这些限制条件的分配证书的所有选项中选择一种,最大化获得一等证书的学生人数。如果存在多个这样的选项,则选择能最大化获得二等证书的学生人数的选项。如果存在多个这样的选项,则选择能最大化获得三等证书的选项。 你要保证所述限制条件使得可以选择一种分配证书的方式,以便奥林匹克竞赛的所有 $n$ 名参赛者都能获得某个等级的证书。 #### 输入格式 输入的第一行包含一个整数 $n$ $(3 \le n\le 3\cdot10^6)$——将参加奥林匹克竞赛的学生人数。 输入的第二行包含两个整数 $\min_1$ 和 $\max_1$$(1\le \min_1 \le \max_1 \le10^6)$——可以分发的一等证书的最低和最高限制。 输入的第三行包含两个整数 $\min_2$ 和 $\max_2$$(1\le \min_2 \le \max_2 \le10^6)$——可以分发的二等证书的最低和最高限制。 输入的第四行包含两个整数 $\min_3$ 和 $\max_3$$(1\le \min_3 \le \max_3 \le10^6)$——可以分发的三等证书的最低和最高限制。 保证 $\min_1+\min_2+\min_3\le n\le\max_1+\max_2+\max_3$。 #### 输出格式 在输出的第一行中打印三个数字,表示在最佳的证书分配方案中将授予学生一、二和三等证书的数量。 最佳的证书分配方案是最大化获得一等证书的学生人数的方案。在所有合适的选项中,最佳方案是最大化获得二等证书的学生人数的方案。如果存在多个这样的选项,则最佳方案是最大化获得三等证书的方案。 Translate By @[ZeXic_B](https://www.luogu.com.cn/user/661274)

加入题单

上一题 下一题 算法标签: