B. Before an Exam

题目连接:

http://www.codeforces.com/contest/4/problem/B

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 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.

Sample Input

1 48

5 7

Sample Output

NO

Hint

题意

有n天,你一共学习了m个小时。

这n天每天你必须学习li个小时,但是不能超过ri小时。

问你m个小时能不能合理分配,满足这n天的要求。

如果可以,输出方案。

题解:

直接dp就好了,dp[i][j]表示到了第i天,一共学习了j个小时。

然后记录一下从哪儿转移过来的就好了。

不过数据范围好小,估计怎么做都可以……

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 35;
int n,m;
int l[maxn],r[maxn];
int dp[35][1200],from[35][1200];
void solve(int x,int y)
{
if(x!=1)solve(x-1,from[x][y]);
printf("%d ",y-from[x][y]);
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
scanf("%d%d",&l[i],&r[i]);
dp[0][0]=1;
for(int i=1;i<=n;i++)
{
for(int j=0;j<1000;j++)
{
if(dp[i-1][j])
{
for(int k=l[i];k<=r[i];k++)
{
dp[i][j+k]=1;
from[i][j+k]=j;
}
}
}
}
if(dp[n][m])
{
cout<<"YES"<<endl;
solve(n,m);
}
else cout<<"NO"<<endl;
}

最新文章

  1. [Java 缓存] Java Cache之 Guava Cache的简单应用.
  2. Replication的犄角旮旯(六)-- 一个DDL引发的血案(上)(如何近似估算DDL操作进度)
  3. iOS开发关于Block代码错误
  4. HTML基础 整理
  5. 转载 javascript中的正则表达式总结 二
  6. ACE - Ubuntu下环境搭建
  7. 黑马程序员-- .net基础加强8之委托,事件,程序集
  8. https://github.com/mlzboy/spider-impl.git
  9. CI 笔记 数据库
  10. BootStrap 智能表单系列 十 自动完成组件的支持
  11. Oracle 中的Top写法
  12. 在阿里云ECS(CentOS6.5)上安装jdk
  13. CentOS 6.3 64位下MySQL5.1.54源码安装配置详解
  14. python全栈学习--day3
  15. 个人作业2——NBA 2k18案例分析
  16. 人手一份核武器 - Hacking Team 泄露(开源)资料导览手册
  17. tp5 整合 个推
  18. 羊车门问题(Python)
  19. 洛谷P1725--琪露诺(单调队列)
  20. (转)redis分布式锁-SETNX实现

热门文章

  1. Android中的通信Volley
  2. LCD常用接口原理【转】
  3. 安装Https证书
  4. CSS3 object-fit 图像裁剪
  5. openssh升级步骤
  6. plsql实例精讲部分笔记
  7. C++的黑科技(深入探索C++对象模型)
  8. java.lang.reflect.UndeclaredThrowableExceptionjiang
  9. 安装 jupyter notebook 出现 ModuleNotFoundError: No module named &#39;markupsafe._compat&#39; 错误
  10. System.Net.Mail的应用,后端发送邮件