描述:
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.
输入:
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.
输出:
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.
样例输入:
1 48 5 7
样例输出:
NO
样例输入:
2 5 0 1 3 5
样例输出:
YES 1 4
描述:
明天彼得有一场生物考试。他不太喜欢这门课程,但d天前他得知他必须参加这门考试。彼得严格的父母让他立即准备考试,为此,他每第i天的学习必须不少于minTimei小时,不超过maxTimei 小时。此外,他们警告彼得,考试前一天,他们会检查他是如何遵守他们的指示的。
所以,今天是彼得的父母要求他出示准备的学习时间表的日子。但是这个男孩只计算了他在准备上花费的时间总和sumTime,现在他想知道他是否能给他的父母展示一个带有d数字的时间表,其中每个数字sсhedulei 代表彼得每第i天在生物学习上所花费的时间,以小时为单位,并满足他父母施加的限制,与此同时,所有sсhedulei的总和应该等于sumTime。
输入:
第一行输入包括两个整数d, sumTime (1 ≤ d ≤ 30, 0 ≤ sumTime ≤ 240)——在此期间彼得学习的天数,以及在准备上花费的总小时数。接下来的每一行都包括两个整数minTimei, maxTimei (0 ≤ minTimei ≤ maxTimei ≤ 8),被一个空格隔开,表示彼得在第i天可以花费的最小和最大小时数。
输出:
如果彼得遵守他父母的指示,在第一行输出YES,并且在第二行输出d数字(用空格分隔),每一个数字代表他在相应的一天里花费在准备上的小时数;否则在唯一的一行输出NO。如果有多种解决方案,输出任意一种即可。
样例输入:
1 48 5 7
样例输出:
NO
样例输入:
2 5 0 1 3 5
样例输出:
YES 1 4
题目地址链接:Problem - B - Codeforces