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

转载于:https://www.cnblogs.com/qscqesze/p/5293318.html

Codeforces Beta Round #4 (Div. 2 Only) B. Before an Exam dp相关推荐

  1. Codeforces Beta Round #9 (Div. 2 Only) D. How many trees? dp

    D. How many trees? 题目连接: http://www.codeforces.com/contest/9/problem/D Description In one very old t ...

  2. Codeforces Beta Round #75 (Div. 1 Only) B. Queue 线段树。单点更新

    http://codeforces.com/problemset/problem/91/B 题意: 给你n个数,求得i 到n中小于a[i]的最右边的a[j],然后求a[i]到a[j]之间包含了多少个数 ...

  3. Codeforces Beta Round #22 (Div. 2 Only) E. Scheme(DFS+强连通)

    题目大意 给了 n(2<=n<=105) 个点,从每个点 u 出发连向了一个点 v(共 n 条边) 现在要求添加最少的边使得整个图是一个强连通图 做法分析 这道题千万不要一般化:先求强连通 ...

  4. Codeforces Beta Round #4 (Div. 2 Only)

    Codeforces Beta Round #4 (Div. 2 Only) A 水题 1 #include<bits/stdc++.h> 2 using namespace std; 3 ...

  5. Codeforces Beta Round #92 (Div. 1 Only) A. Prime Permutation 暴力

    A. Prime Permutation 题目连接: http://www.codeforces.com/contest/123/problem/A Description You are given ...

  6. Codeforces Beta Round #14 (Div. 2) B. Young Photographer 水题

    B. Young Photographer 题目连接: http://codeforces.com/contest/14/problem/B Description Among other thing ...

  7. Codeforces Beta Round #96 (Div. 1) D. Constants in the language of Shakespeare 贪心

    D. Constants in the language of Shakespeare Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codef ...

  8. Codeforces Beta Round #9 (Div. 2 Only) C. Hexadecimal's Numbers dfs

    C. Hexadecimal's Numbers 题目连接: http://www.codeforces.com/contest/9/problem/C Description One beautif ...

  9. Codeforces Beta Round #16 (Div. 2 Only)【未完结】

    2022.3.9 题目地址:https://codeforces.com/contest/16 目录 A. Flag[模拟] B. Burglar and Matches[贪心] C. Monitor ...

最新文章

  1. 我虐小车千百遍,小车待我如初恋
  2. JAVA写HTTP代理服务器(三)-https明文捕获
  3. java中日期怎么_Java 中的日期处理
  4. 10g添加用户 oracle_oracle 10g中如何创建用户
  5. 用自定义注解做点什么——自定义注解有什么用
  6. 防止U盘中病毒的小技巧
  7. Android WebView 网页使用本地字体
  8. 【层级多标签文本分类】基于预训练语言模型的BERT-CNN多层级专利分类研究
  9. 利用RTFtemplate生成rtf报表
  10. 利用python提取企查查企业的工商基本信息
  11. Gstore官网学习六:安装和部署workbench(自带填坑)
  12. mysql 主辅_Mysql的实时同步 - 主辅同步
  13. C++中的堆内存、栈内存和静态内存
  14. ATFX:5年期LPR利率大降15基点,USDCNH涨破年内高点
  15. 解决创建Maven Project出现的项目报错问题
  16. 迅雷文件创建失败无法下载
  17. Android自定义控件eBook翻书效果
  18. 如何弹出QQ临时对话框,实现不添加好友的在线交谈效果。
  19. RV1109_RV1126 EVB板使用总结
  20. 如何打开7z格式的压缩文件?

热门文章

  1. 学完php在学python_写给PHP程序员的 Python学习指南(建议去看原文)
  2. Java基础知识强化之集合框架笔记27:ArrayList集合练习之去除ArrayList集合中的重复字符串元素...
  3. WPF自定义控件 —— 装饰器
  4. [调试]Asp.Net常见问题
  5. 04级函授计算机等级考试练习.rar
  6. 超导量子计算机速度多快,我国量子计算机实现量子霸权,计算速度比谷歌快了100亿倍...
  7. php中for循环流程图,PHP for循环
  8. css p 文本不换行,超出文字显示省略号
  9. java同步读写,关于java:Collections中的synchronizedMap方法是否同步读写操作
  10. java导出excel文件名_怎么解决java导出excel时文件名乱码