博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Ilya and Diplomas (贪心5)
阅读量:5770 次
发布时间:2019-06-18

本文共 3526 字,大约阅读时间需要 11 分钟。

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
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 
#include
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;}

 

转载于:https://www.cnblogs.com/tianmin123/p/4638848.html

你可能感兴趣的文章
一些软件设计的原则
查看>>
JSP代码段中直接访问值valuestack栈内容(转)
查看>>
使用 Charles 获取 https 的数据
查看>>
相对路径和绝对路径的问题
查看>>
Cocos2dx-OpenGL ES2.0教程:使用VBO索引(4)
查看>>
Keepalived 配置电信/联通双线高可用集群
查看>>
2014年3月15日参加阿里技术大讲堂技术保障专场
查看>>
关于Linux进程的一些收获
查看>>
Go编程笔记(10)
查看>>
利用XMPP协议推送服务器告警信息到安卓平台及桌面
查看>>
Android APP实现语言切换功能
查看>>
如何查看计算机端口状态
查看>>
Linux学习记录--软件安装RPM|SRPM|YUM
查看>>
Git基础之(十九)——标签管理
查看>>
VMware vSphere 5.1 群集深入解析(十)
查看>>
java性能优化 –gc日志收集与分析
查看>>
将h.264视频流封装成flv格式文件
查看>>
postgresql 删除 数据库,表,索引
查看>>
java编程中的反射问题
查看>>
oracle 表空间查询
查看>>