Before an Exam

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 

题目大意:皮特每天要复习一定的时间,第一行中的两个数字分别表示一共要复习几天,第二个数字是这些天需要复习的总时间,而问题则是皮特每天需要复习多长时间符合要求.若符合输出YES并且将每一天的学习时间记录下来,若不符合就直接输出NO.而这个问题首先要搞懂的则是每天都有应有的学习时间,每天要学习的学习时间是大于等于最短时间的.所以总时间要减去所有的最短时间的总和后在遍历.代码如下:

#include<stdio.h>
#include<string.h>
int main()
{
    int sum,n;
    int i,j;
    int a[1000],b[1000],c[1000];
    int maxx,minn;
    while(scanf("%d %d",&n,&sum)!=EOF)
    {
        memset(c,0,sizeof(c));//两个时间的区间长度
         memset(b,0,sizeof(b));//两个时间段中的最大时间
          memset(a,0,sizeof(a));//两个时间段中的最小时间


        minn=0;
        maxx=0;
        for(i=0; i<n; i++)
        {
            scanf("%d %d",&a[i],&b[i]);
            c[i]=b[i]-a[i];
            minn=minn+a[i];//将每天学习的最短时间加起来
            maxx=maxx+b[i];//将每天学习的最长时间加起来
        }
        if(sum<minn||sum>maxx)//若是需要的总时间不在这个范围内则输出NO
            printf("NO\n");
        else
        {
            printf("YES\n");
            sum-=minn;
            for(i=0; i<n; i++)
            {
                if(sum>=c[i])//若是sum在减去所有最短时间后还是大于区间长度那就输出这个区间的最大值
                {
                    printf("%d ",b[i]);
                    sum=sum-c[i];
                }


                else if(sum==0)//若为零则直接输出最小值
                {
                    printf("%d ",a[i]);
                }
                else if(sum<c[i]){//若小于区间长度那么1就将剩下的sum全部附给这个区间
                      printf("%d ",sum+a[i]);
                        sum=0;
                }
            }
            printf("\n");
        }

    }

    return 0;
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值