代码:
#include <stdio.h>
#include <queue>
#include <algorithm>
#include <vector>
using namespace std;
const int MAXN = 35;
const int INF = 1 << 30;
int maxDay[MAXN], minDay[MAXN];
int main()
{
#ifdef _LOCAL
freopen("F://input.txt", "r", stdin);
#endif
int d, sumTime;
scanf("%d%d", &d, &sumTime);
int maxHour = 0, minHour = 0;
for(int i = 1; i <= d; i++)
{
scanf("%d%d", &minDay[i], &maxDay[i]);
maxHour+= maxDay[i];
minHour+= minDay[i];
}
if(sumTime > maxHour || sumTime < minHour)
{
printf("NO\n");
return 0;
}
int need = maxHour - sumTime;
for(int i = 1; i <= d && need; ++i)
{
if(maxDay[i] - minDay[i] >= need)
{
maxDay[i] -= need;
need = 0;
}
else if(maxDay[i] - minDay[i] < need)
{
need -= maxDay[i] - minDay[i];
maxDay[i] = minDay[i];
}
}
printf("YES\n");
for(int i = 1; i <= d; ++i)
printf("%d ", maxDay[i]);
}