CodeForces #4B. Before an Exam
2016-03-13 13:43
429 查看
B. Before an Exam
time limit per test
0.5 second
memory limit per test
64 megabytes
input
standard input
output
standard output
Tomorrow Peter has a Biology exam. He does not like this subject much, but d days ago he learnt that he would have to take this exam.
Peter's strict parents made him prepare for the exam immediately, for this purpose he has to study not less than minTimei and
not more than maxTimei hours
per each i-th day. Moreover, they warned Peter that a day before the exam they would check how he has followed their instructions.
So, today is the day when Peter's parents ask him to show the timetable of his preparatory studies. But the boy has counted only the sum of hours sumTime spent
him on preparation, and now he wants to know if he can show his parents a timetable sсhedule with dnumbers,
where each number sсhedulei stands
for the time in hours spent by Peter each i-th day on biology studies, and satisfying the limitations imposed by his parents, and
at the same time the sum total of all schedulei should
equal to sumTime.
Input
The first input line contains two integer numbers d, sumTime (1 ≤ d ≤ 30, 0 ≤ sumTime ≤ 240)
— the amount of days, during which Peter studied, and the total amount of hours, spent on preparation. Each of the following d lines
contains two integer numbersminTimei, maxTimei (0 ≤ minTimei ≤ maxTimei ≤ 8),
separated by a space — minimum and maximum amount of hours that Peter could spent in the i-th day.
Output
In the first line print YES, and in the second line print d numbers
(separated by a space), each of the numbers — amount of hours, spent by Peter on preparation in the corresponding day, if he followed his parents' instructions; or print NO in
the unique line. If there are many solutions, print any of them.
Examples
input
output
input
output
题目大意:
要求在n天内学习t小时,给出每一天可以学习的最小时间和最大时间。问能不能实现,若可以输出时间表。
解题思路:
保证在区间范围内的情况下直接贪心。
time limit per test
0.5 second
memory limit per test
64 megabytes
input
standard input
output
standard output
Tomorrow Peter has a Biology exam. He does not like this subject much, but d days ago he learnt that he would have to take this exam.
Peter's strict parents made him prepare for the exam immediately, for this purpose he has to study not less than minTimei and
not more than maxTimei hours
per each i-th day. Moreover, they warned Peter that a day before the exam they would check how he has followed their instructions.
So, today is the day when Peter's parents ask him to show the timetable of his preparatory studies. But the boy has counted only the sum of hours sumTime spent
him on preparation, and now he wants to know if he can show his parents a timetable sсhedule with dnumbers,
where each number sсhedulei stands
for the time in hours spent by Peter each i-th day on biology studies, and satisfying the limitations imposed by his parents, and
at the same time the sum total of all schedulei should
equal to sumTime.
Input
The first input line contains two integer numbers d, sumTime (1 ≤ d ≤ 30, 0 ≤ sumTime ≤ 240)
— the amount of days, during which Peter studied, and the total amount of hours, spent on preparation. Each of the following d lines
contains two integer numbersminTimei, maxTimei (0 ≤ minTimei ≤ maxTimei ≤ 8),
separated by a space — minimum and maximum amount of hours that Peter could spent in the i-th day.
Output
In the first line print YES, and in the second line print d numbers
(separated by a space), each of the numbers — amount of hours, spent by Peter on preparation in the corresponding day, if he followed his parents' instructions; or print NO in
the unique line. If there are many solutions, print any of them.
Examples
input
1 48 5 7
output
NO
input
2 5 0 1 3 5
output
YES 1 4
题目大意:
要求在n天内学习t小时,给出每一天可以学习的最小时间和最大时间。问能不能实现,若可以输出时间表。
解题思路:
保证在区间范围内的情况下直接贪心。
#include <cstdio> using namespace std; struct node { int min1, max1; }da[35]; int main() { int d, t, uplim = 0, downlim = 0; scanf("%d%d", &d, &t); for (int i = 0; i < d; i++){ scanf("%d%d", &da[i].min1, &da[i].max1); downlim += da[i].min1; uplim += da[i].max1; } if (uplim < t || downlim > t) printf("NO\n"); else{ printf("YES\n"); t -= downlim; for (int i = 0; i < d; i++){ if (t >= da[i].max1 - da[i].min1){ printf("%d ", da[i].max1); t -= da[i].max1 - da[i].min1; } else if (t == 0){ printf("%d ", da[i].min1); } else if (t < da[i].max1 - da[i].min1){ printf("%d ", t + da[i].min1); t = 0; } } } return 0; }
相关文章推荐
- 基于python利用爬虫爬取网页教程
- 第二周学习进度
- 现有分布式技术(socket、.net remoting、asp.net webservice、WSE、ES)和wcf的比较及优势
- 通过sleep_for来使线程睡眠一定的时间
- vs2010 代码自动排版快捷键
- 在ios中运用core animation暂停和继续动画
- php 打印、显示、输出函数 收集
- 剑指offer-链表中倒数第k个结点
- java 命名规范
- 关键帧动画CAKeyframeAnimation
- Tomcat下的JAAS实例
- C/C++语言执行效率的优化方法(待续)
- 安卓蓝牙开发的几个版本区别
- linux内核分析学习笔记:用gdb跟踪linux内核启动过程
- IOS动画Core Animation详解
- [LeetCode235]Lowest Common Ancestor of a Binary Search Tree
- 防止脱发的具体方法
- 第一个小应用:图片浏览器 之 四 读写SD卡
- test一下博客怎么写
- hdu3033I love sneakers!【分组背包】每组至少取一个