B题 Before an Exam

Description

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.

Sample Input

Input
1 48 
5 7
Output
NO
Input
2 5 
0 1
3 5
Output
YES 
1 4

题意:

AC代码:

 1 #include<iostream>
 2 #include<cstdio>
 3 
 4 using namespace std;
 5 
 6 int main()
 7 {
 8     int mintime[32]={0},maxtime[32];
 9     int n,sum;
10     cin>>n>>sum;
11     int i,j;
12     for(i=1;i<=n;i++){
13         cin>>mintime[i%n]>>maxtime[i%n];
14         sum-=mintime[i%n];
15     }
16     if(sum<0){cout<<"NO"<<endl;return 0;}
17     if(sum==0){
18         cout<<"YES"<<endl;
19         for(i=1;i<=n;i++)cout<<mintime[i%n]<<" ";
20         cout<<endl;return 0;
21     }
22     i=1;
23     int k=sum,s=0;
24     while(1){
25         if(mintime[i]<maxtime[i]){
26             mintime[i]++;
27             sum--;
28             if(sum==0){
29                 cout<<"YES"<<endl;
30                 for(j=1;j<=n;j++)cout<<mintime[j%n]<<" ";
31                 cout<<endl;return 0;
32             }
33         }
34         if(k==sum){
35             s++;
36             if(s==n+1)break;
37         }
38         else {k=sum;s=0;}
39         i++;
40         i%=n;
41     }
42     cout<<"NO"<<endl;
43     return 0;
44 }
View Code

 

 

转载于:https://www.cnblogs.com/zhangchengbing/p/3233449.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值