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;
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章