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 ...
随机推荐
- CodeForces 675E Trains and Statistic
贪心,递推,线段树,$RMQ$. 假设我们记$ans[i]$是以$i$点为起点对答案的贡献,那么答案就是$\sum\limits_{i = 1}^n {ans[i]}$. $ans[i]$怎么计算呢? ...
- 关于The requested PHP extension ext-pdo_sqlite * is missing from your system. Install or enable PHP's pdo_sqlite extension.的解决
$ php composer.phar install Loading composer repositories with package information Installing depend ...
- JDK各版本新增的主要特性
JDK1.5新特性: 1.自动装箱与拆箱: 2.枚举 3.静态导入,如:import staticjava.lang.System.out 4.可变参数(Varargs) 5.内省(Introspec ...
- mozilla your firefox profile cannot be loaded. it may be missing or inaccessible
check the permissions ls -l ~/.cache | grep mozilla fix the permissions sudo chown -R $USER:$USER ~/ ...
- HDOJ_就这么个烂题总是WA先放这把
#include<stdio.h> __int64 A[100]={0}; __int64 B[100]={0}; __int64 SUM[100]={0}; int main() {in ...
- Abstract和Virtual
在C#的学习中,容易混淆virtual方法和abstract方法的使用,现在来讨论一下二者的区别. 它们有一个共同点:二者都是用来修饰父类的,只能作为基类使用,通过覆盖父类的定义,让子类与overri ...
- C# 中获取时区列表
c#中获取时区列表 下面方法获得的仅仅用来显示和使用,无法用来进行时间转换. public static List<DisplayTimeZone> GetSystemTimeZones( ...
- C# winform Datagridview 标题居中
DataGridView1.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
- Meta标签中的format-detection属性及含义让IPHONE的数字可以改变颜色
format-detection翻译成中文的意思是“格式检测”,顾名思义,它是用来检测html里的一些格式的,那关于meta的format-detection属性主要是有以下几个设置: meta na ...
- Kruskal算法的简单实现
嘛嘛嘛,好像大家在实现Kruskal算法是都是用的边集数组,判断图的连通性咱不会,o(╯□╰)o(为什么咱这么菜诶) Kruskal算法: 规则: (1)对每一条边按照从小到大进行排序 (2)加入边的 ...