A. Ilya and Diplomas( Codeforces Round #311 (Div. 2) )
1 second
256 megabytes
standard input
standard output
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 mostmax2 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 nparticipants
of the Olympiad will receive a diploma of some degree.
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.
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.
6
1 5
2 6
3 7
1 2 3
10
1 2
1 3
1 5
2 3 5
6
1 3
2 2
2 2
2 2 2
题意:给出3个区间 [L1,R1],[L2,R2],[L3,R3] 和正整数n,要求在3个区间内各选一个正整数。使得选出来的数之和为n。假设有多种选法,取从第一个区间内选出的
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<stdlib.h> using namespace std; int n;
struct node
{
int minn;
int maxx;
}q[5]; int main()
{
while(scanf("%d",&n)!=EOF)
{
for(int i=1;i<=3;i++)
{
scanf("%d%d",&q[i].minn,&q[i].maxx);
}
int a[5];
int sum = n;
memset(a,0,sizeof(a));
for(int i=1;i<=3;i++)
{
a[i] = q[i].minn;
sum -= a[i];
}
for(int i=1;i<=3;i++)
{
int num = q[i].maxx - q[i].minn;
if(sum>=num)
{
a[i] += num;
sum -= num;
}
else
{
a[i] += sum;
break;
}
}
printf("%d %d %d\n",a[1],a[2],a[3]);
}
return 0;
}
A. Ilya and Diplomas( Codeforces Round #311 (Div. 2) )的更多相关文章
- 【CodeForces】841D. Leha and another game about graph(Codeforces Round #429 (Div. 2))
[题意]给定n个点和m条无向边(有重边无自环),每个点有权值di=-1,0,1,要求仅保留一些边使得所有点i满足:di=-1或degree%2=di,输出任意方案. [算法]数学+搜索 [题解] 最关 ...
- C. Arthur and Table(Codeforces Round #311 (Div. 2) 贪心)
C. Arthur and Table time limit per test 1 second memory limit per test 256 megabytes input standard ...
- B. Ohana Cleans Up(Codeforces Round #309 (Div. 2))
B. Ohana Cleans Up Ohana Matsumae is trying to clean a room, which is divided up into an n by n gr ...
- B. The Number of Products(Codeforces Round #585 (Div. 2))
本题地址: https://codeforces.com/contest/1215/problem/B 本场比赛A题题解:https://www.cnblogs.com/liyexin/p/11535 ...
- 【CodeForces】841C. Leha and Function(Codeforces Round #429 (Div. 2))
[题意]定义函数F(n,k)为1~n的集合中选择k个数字,其中最小数字的期望. 给定两个数字集A,B,A中任意数字>=B中任意数字,要求重组A使得对于i=1~n,sigma(F(Ai,Bi))最 ...
- D. Zero Quantity Maximization ( Codeforces Round #544 (Div. 3) )
题目链接 参考题解 题意: 给你 整形数组a 和 整形数组b ,要你c[i] = d * a[i] + b[i], 求 在c[i]=0的时候 相同的d的数量 最多能有几个. 思路: 1. 首先打开 ...
- Vus the Cossack and Strings(Codeforces Round #571 (Div. 2))(大佬的位运算实在是太强了!)
C. Vus the Cossack and Strings Vus the Cossack has two binary strings, that is, strings that consist ...
- CodeForces 360E Levko and Game(Codeforces Round #210 (Div. 1))
题意:有一些无向边m条权值是给定的k条权值在[l,r]区间可以由你来定,一个点s1 出发一个从s2出发 问s1 出发的能不能先打到f 思路:最短路. 首先检测能不能赢 在更新的时候 如果对于一条边 ...
- 贪心+构造( Codeforces Round #344 (Div. 2))
题目:Report 题意:有两种操作: 1)t = 1,前r个数字按升序排列: 2)t = 2,前r个数字按降序排列: 求执行m次操作后的排列顺序. #include <iostream&g ...
随机推荐
- Mysql学习总结(30)——MySQL 索引详解大全
什么是索引? 1.索引 索引是表的目录,在查找内容之前可以先在目录中查找索引位置,以此快速定位查询数据.对于索引,会保存在额外的文件中. 索引,是数据库中专门用于帮助用户快速查询数据的一种数据结构.类 ...
- FROM使用子查询
FROM使用子查询 子查询结果充当一个临时表. //子查询形成的临时表字段为NO,NAME,SAL select no,name from( select empno no,e ...
- 洛谷 1156 dp
洛谷1156 dp 类背包问题 老久没有自己想出来过dp方程了,,,虽然到最后还是只写了30分,,, 设dp[j]表示最大生命值为i时的最大高度,则对于每个物品,可以选择吃掉或者放上去,即转移为dp[ ...
- 洛谷 P2243 电路维修
P2243 电路维修 题目背景 Elf 是来自Gliese 星球的少女,由于偶然的原因漂流到了地球上.在她无依无靠的时候,善良的运输队员Mark 和James 收留了她.Elf 很感谢Mark和Jam ...
- Linux多线程实践(四 )线程的特定数据
在单线程程序中.我们常常要用到"全局变量"以实现多个函数间共享数据, 然而在多线程环境下.因为数据空间是共享的.因此全局变量也为全部线程所共同拥有.但有时应用程序设计中有必要提供线 ...
- string 简单实现
namespace ss{ class string { friend ostream& operator <<(ostream&, const string&); ...
- Swift开发教程--怎样使UITableViewController背景透明
self.tableView.backgroundView? .backgroundColor = UIColor.clearColor(); self.tableView.backgroundCol ...
- NYOJ 915 +-字符串【贪心】
+-字符串 时间限制:1000 ms | 内存限制:65535 KB 难度:1 描写叙述 Shiva得到了两个仅仅有加号和减号的字符串,字串长度同样.Shiva一次能够把一个加号和它相邻的减号交换 ...
- CCControlExtension/CCControlPotentiometer
#ifndef __CCCONTROLPOTENTIOMETER_H__ #define __CCCONTROLPOTENTIOMETER_H__ #include "CCControl.h ...
- OSGi 和 C++
2011年 9月我参加了OSGi社区在达姆施塔特的会议,并且有机会与其他与会者探讨本机c++实现的OSGi规范的现状.在这一事件之前我也一直想写一篇博客,来描述关于当前实现OSGi规范的现状和努力—— ...