您的位置:首页 > 其它

codeforce 4B(思维水题)

2017-05-26 11:23 399 查看
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 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 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 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.

Example

Input
1 48
5 7


Output
NO


Input
2 5
0 1
3 5


Output
YES
1 4


/*题意:给你一个d表示前d天,给你一个sumtime表示应该复习的时间。接下来d行表示每天的最少复习时间和最多复习时间,你可以复习时间在这个区间内。题意在考试前d天开始复习,判断是否存在每天复习时间加起来等于sumtime,并打印每天复习时间*/

/*思路:按照每天最小时间复习加起来,如果小于sumtime,那么总的最小时间减去第一天的复习时间加上选第一天时间区间的其他数如果相等输出,如果加上第一天最大时间任然小于那么第一天复习时间就为最大值,继续向第二天枚举,以此类推找到最大的。数字小直接暴力(注意特判若最小天数的和或最大天数的和恰好等于sumtime)(第一次想复杂了写了好多)*/

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

int d, sumtime;
struct node{
int s, e, index;
}day[50];

void print()
{
for(int i = 0; i < d - 1; i++)
printf("%d ", day[i].s);
printf("%d\n", day[d-1].s);
return ;
}

int main()
{
while(scanf("%d%d", &d, &sumtime) != EOF){
int sums = 0;
int sume = 0;
for(int i = 0; i < d; i++){
scanf("%d%d", &day[i].s, &day[i].e);
day[i].index = i + 1;
sums += day[i].s;
sume += day[i].e;
}
int flag = 0;
if(sums <= sumtime && sume >= sumtime){
printf("YES\n");
flag = 1;
}
else if(sumtime < sums || sumtime > sume){
printf("NO\n");
continue;
}
int flag1 = 0;
if(flag){
if(sums == sumtime){
print();
flag1 = 1;
}
if(flag1)
continue;
if(sume == sumtime){
for(int i = 0; i < d; i++)
day[i].s = day[i].e;	//因为我始终跟新的一天最少的复习时间
print();
flag1 = 1;
}
if(flag1)
continue;
if(sums < sumtime && sume > sumtime){
for(int i = 0; i < d; i++){
if(day[i].s == day[i].e)
continue;
for(int j = day[i].s; j < day[i].e;){
sums -= day[i].s;
j = j + 1;
sums += j;
day[i].s = j;
if(sums == sumtime)
print();
}
}
}
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: