B题 Before an Exam
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 dnumbers, 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 numbersminTimei, 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
NO
2 5
0 1
3 5
YES
1 4
题意:
AC代码:
#include<iostream>
#include<cstdio> using namespace std; int main()
{
int mintime[]={},maxtime[];
int n,sum;
cin>>n>>sum;
int i,j;
for(i=;i<=n;i++){
cin>>mintime[i%n]>>maxtime[i%n];
sum-=mintime[i%n];
}
if(sum<){cout<<"NO"<<endl;return ;}
if(sum==){
cout<<"YES"<<endl;
for(i=;i<=n;i++)cout<<mintime[i%n]<<" ";
cout<<endl;return ;
}
i=;
int k=sum,s=;
while(){
if(mintime[i]<maxtime[i]){
mintime[i]++;
sum--;
if(sum==){
cout<<"YES"<<endl;
for(j=;j<=n;j++)cout<<mintime[j%n]<<" ";
cout<<endl;return ;
}
}
if(k==sum){
s++;
if(s==n+)break;
}
else {k=sum;s=;}
i++;
i%=n;
}
cout<<"NO"<<endl;
return ;
}
B题 Before an Exam的更多相关文章
- EGener2四则运算出题器
项目源码: https://git.coding.net/beijl695/EGener2.git (代码纯属原创,设计细节不同,请思量) 项目发布后,由于期间各种事情,耽搁至最后一天交付.这次的项目 ...
- jloi2017(shoi2017?)六省联考酱油记
Day -n 听说了4.22.4.23的省选,而且还是六省联考. 压力山大. 尽管我只是一名高一的simple OIer,在省选到来之前,心里还是很紧张的. 毕竟自己也知道南方dalao们都是神犇,像 ...
- 2018 ACM-ICPC青岛现场赛 B题 Kawa Exam 题解 ZOJ 4059
题意:BaoBao正在进行在线考试(都是选择题),每个题都有唯一的一个正确答案,但是考试系统有m个bug(就是有m个限制),每个bug表示为第u个问题和第v个问题你必须选择相同的选项,题目问你,如果你 ...
- noi题库(noi.openjudge.cn) 1.7编程基础之字符串T21——T30
T21:单词替换 描述 输入一个字符串,以回车结束(字符串长度<=100).该字符串由若干个单词组成,单词之间用一个空格隔开,所有单词区分大小写.现需要将其中的某个单词替换成另一个单词,并输出替 ...
- Java IO流题库
一. 填空题 Java IO流可以分为 节点流 和处理流两大类,其中前者处于IO操作的第一线,所有操作必须通过他们进行. 输入流的唯一目的是提供通往数据的通道,程序可以通过这个通道读取数 ...
- OCJP(1Z0-851) 模拟题分析(一)11
Exam : 1Z0-851 Java Standard Edition 6 Programmer Certified Professional Exam 以下分析全都是我自己分析或者参考网上的,定有 ...
- ocp 1Z0-042 1-60题解析
1. Because of a power outage,instance failure has occurred. From what point in the redo log does rec ...
- URAL 2056 Scholarship 水题
ScholarshipTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.a ...
- Exam 70-462 Administering Microsoft SQL Server 2012 Databases 复习帖
好吧最近堕落没怎么看书,估计这个月前是考不过了,还是拖到国庆之后考试吧.想着自己复习考试顺便也写点自己的复习的概要,这样一方面的给不准备背题库的童鞋有简便的复习方法(好吧不被题库的同学和我一样看MSD ...
随机推荐
- 学习smail注入遇到的坑
1.将需要被反编译的apk包解开之后,找到MainActivity,然后在OnCreate中添加需要加入注入的smail代码: Java代码: /** * 获取Android id * * @para ...
- Openjudge-NOI题库-简单算术表达式求值
题目描述 Description 两位正整数的简单算术运算(只考虑整数运算),算术运算为: +,加法运算:-,减法运算:*,乘法运算:/,整除运算:%,取余运算. 算术表达式的格式为(运算符前后可能有 ...
- ubuntu开放防火墙端口
root@jbxue:$ sudo ufw enable Firewall started and enabled on system startup root@jbxue:$ sudo ufw ...
- some idea for my personal page
firstly, dump the old personal page source from Github to Dropbox.then the idea is: 1: make a fake s ...
- web端和手机端测试有什么不同
面试中经常被问到web端测试和手机端测试有什么相同点和区别呢?现在总结一下这个问题,如有不对敬请指正 web端和手机端测试有什么区别 1.相同点 不管是web测试还是手机App测试,都离不开测试的相关 ...
- 元素的BFC特性与自适应布局
一.BFC元素简介与基本表现. BFC全程"Block Formatting Context",中文为"块级格式化上下文".记住一句话:BFC元素特性表现原则就 ...
- yii2.0 面包屑的使用
yii2中面包屑是yii2自带的小部件,类似本网站的导航栏应该就是采用面包屑来完成的 例子如下,需要引入 yii\widgets\Breadcrumbs echo Breadcrumbs::widge ...
- python自动化Traceback (most recent call last):报错
今天使用python.然而遇见了Traceback (most recent call last):的报错.抓狂的一笔.有说path写错的,有说是...网上查到的资料也是很少.后来突然发现,页面上我暂 ...
- WI-FI: connection through CLI
First, ensure that the computer/sbc has WI-FI parts. install wpa_supplicant, edit /etc/wpa_supplican ...
- 对比git pull和git pull --rebase
1.使用下面的关系区别这两个操作:git pull = git fetch + git mergegit pull --rebase = git fetch + git rebase 2 一.基本 g ...