B. Before an Exam

来源:互联网 发布:java和c语言的区别 编辑:程序博客网 时间:2024/04/27 21:06

time limit per test
1 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 thanminTimei 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 timetablesсhedule with d numbers, 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 scheduleishould 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 numbers minTimei, 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.

Sample test(s)
input
1 485 7
output
NO
input
2 50 13 5
output
YES1 4 

解题说明:题目意思翻译过来就是有n组min max值以及一个sum值,现在要求n个介于min和max之间的数,让其和为sum。此题可以先从sum中减去所有的min,然后对剩下的值进行处理,对其分配时不能超过每一对max-min的值,如果能全部分完,则满足要求。


#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <cstring>#include <string>#include<set>#include <algorithm>using namespace std;int main() {int i,j,k,l,sum,d;int a[33],b[33];scanf("%d %d",&d,&sum);for(i=0;i<d;i++) {scanf("%d %d",&a[i],&b[i]);sum -= a[i];}if(sum < 0) { printf("NO\n"); }else{for(i=0;i<d;i++) {if(sum>0) {j = b[i] - a[i];if(j>sum){k=sum;}else{k=j;}sum -= k;a[i] += k;}}if(sum > 0) {printf("NO\n");}else{printf("YES\n");for(i=0;i<d;i++){printf("%d ",a[i]);}printf("\n");}}return 0;}


原创粉丝点击