Codeforces 4B
1293 ワード
#include<iostream>
#include<cstdio>
#include<string>
#include<string.h>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 35;
class node{
public:
int d, u, s;
node(int d_ = -1, int u_ = -1, int s_ = -1):d(d_),u(u_),s(s_){}
};
node nn[maxn];
int main(){
int d, sum, sumd = 0, sumu = 0;
while(cin >> d >> sum){
sumd = 0;
sumu = 0;
memset(nn,0,sizeof(nn));
for(int i = 0; i < d; ++i){
cin >> nn[i].d >> nn[i].u;
nn[i].s = nn[i].u - nn[i].d;
sumd += nn[i].d;
sumu += nn[i].u;
}
//cout << sumd << "\t" << sumu << endl;
if(sumd > sum || sumu < sum){
cout << "NO" << endl;
}
else{
//cout << "YES" << endl;
sum -= sumd;
int i = 0;
for(i = 0; i < d; ++i){
int span = -1;
if(nn[i].s > sum){
nn[i].d += sum;
sum -= sum;
}
else{
nn[i].d += nn[i].s;
sum -= nn[i].s;
}
if(sum <= 0){
break;
}
}
cout << "YES" << endl;
d--;
for(int i = 0; i < d; ++i){
cout << nn[i].d << " ";
}
cout << nn[d].d << endl;
}
}
return 0;
}