A. Ilya and Diplomas

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/557/problem/A

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

6
1 5
2 6
3 7

Sample Output

1 2 3

HINT

题意

a>b>c,a+b+c=n

告诉你a,b,c的取值范围,让你构造出a,b,c的值

题解:

数学题啦

具体看代码~

代码

#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
#define maxn 100005
#define mod 10007
#define eps 1e-9
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{ll x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;
}
//**************************************************************************************int main()
{int n=read();int a[4],b[4];for(int i=1;i<=3;i++)a[i]=read(),b[i]=read();int ans[4];ans[1]=min(n-a[2]-a[3],b[1]);n-=ans[1];ans[2]=min(n-a[3],b[2]);ans[3]=n-ans[2];cout<<ans[1]<<" "<<ans[2]<<" "<<ans[3]<<endl;}

转载于:https://www.cnblogs.com/qscqesze/p/4612209.html

Codeforces Round #311 (Div. 2) A. Ilya and Diplomas 水题相关推荐

  1. Codeforces Round #311 (Div. 2)B. Pasha and Tea 水题

    B. Pasha and Tea Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/557/prob ...

  2. Codeforces Round #370 (Div. 2) A. Memory and Crow 水题

    A. Memory and Crow 题目连接: http://codeforces.com/contest/712/problem/A Description There are n integer ...

  3. Codeforces Round #394 (Div. 2) A. Dasha and Stairs 水题

    A. Dasha and Stairs 题目连接: http://codeforces.com/contest/761/problem/A Description On her way to prog ...

  4. Codeforces Round #404 (Div. 2) B. Anton and Classes 水题

    B. Anton and Classes 题目连接: http://codeforces.com/contest/785/problem/B Description Anton likes to pl ...

  5. Codeforces Round #374 (Div. 2) A. One-dimensional Japanese Crosswor 水题

    A. One-dimensional Japanese Crossword 题目连接: http://codeforces.com/contest/721/problem/A Description ...

  6. Codeforces Round #358 (Div. 2) A. Alyona and Numbers 水题

    A. Alyona and Numbers 题目连接: http://www.codeforces.com/contest/682/problem/A Description After finish ...

  7. Codeforces Round #307 (Div. 2) A. GukiZ and Contest 水题

    A. GukiZ and Contest Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/551/ ...

  8. Codeforces Round #350 (Div. 2) B. Game of Robots 水题

    B. Game of Robots 题目连接: http://www.codeforces.com/contest/670/problem/B Description In late autumn e ...

  9. Codeforces Round #379 (Div. 2) A. Anton and Danik 水题

    A. Anton and Danik 题目连接: http://codeforces.com/contest/734/problem/A Description Anton likes to play ...

最新文章

  1. 2018/02/06
  2. 计算机电缆和控制电缆区别,动力电缆和控制电缆有啥区别?
  3. DIV水平方向居中的几种方法
  4. 数学建模学习笔记——多元回归
  5. pycharm设置字体和背景色
  6. React with Webpack -1: 介绍Helloworld
  7. c语言中各个符号的意义及作用是什么,C语言特殊符号意义
  8. linux6.0设置共享文件夹,[原创] how to virtualbox sharefolder共享文件夹(数据空间)设置全记录...
  9. ERROR: libass not found using pkg-config2
  10. CS61a-2020fall学习笔记
  11. 小白新建C语言程序(VS2019创建C语言编程环境方法详解)
  12. 智能鱼塘远程检测控制系统
  13. 泰勒公式的展开细节解析
  14. Java之字符串数组元素的排列与组合(递归实现)
  15. 数字 IC 技能拓展(18)如何快速上手 FPGA 开发板呢
  16. 深度学习目标检测在游戏领域的应用
  17. 办公室 VR 黄片,骚操作!微软 HoloLens 之父辞职!
  18. 【navicat】定时清除数据库备份,并保留最近7天
  19. 基于Java+SpringBoot+vue实现图书借阅和销售商城一体化系统
  20. 放置江湖服务器维护,放置江湖挂机收益如何最高 挂机收益最高时间分析[图]

热门文章

  1. Python调用MongoDB使用心得
  2. 正则匹配所有包括换行符
  3. docker搭建常见组件
  4. echo服务器(回显服务器)
  5. C++ 多继承和虚继承的内存布局
  6. Zuul Gateway 网关
  7. java: \uxxxx unicode编码
  8. BZOJ 4584 [Apio2016]赛艇
  9. Linux系统篇-文件系统虚拟文件系统
  10. Visual Studio 2010 多定向的支持