Codeforces Round #336 (Div. 2)-608A.水题 608B.前缀和
1 second
256 megabytes
standard input
standard output
Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an elevator in one of its other hotels. The elevator is special — it starts on the top floor, can only move down, and has infinite capacity. Floors are numbered from 0 to s and elevator initially starts on floor s at time 0.
The elevator takes exactly 1 second to move down exactly 1 floor and negligible time to pick up passengers. Genos is given a list detailing when and on which floor passengers arrive. Please determine how long in seconds it will take Genos to bring all passengers to floor 0.
The first line of input contains two integers n and s (1 ≤ n ≤ 100, 1 ≤ s ≤ 1000) — the number of passengers and the number of the top floor respectively.
The next n lines each contain two space-separated integers fi and ti (1 ≤ fi ≤ s, 1 ≤ ti ≤ 1000) — the floor and the time of arrival in seconds for the passenger number i.
Print a single integer — the minimum amount of time in seconds needed to bring all the passengers to floor 0.
3 7
2 1
3 8
5 2
11
5 10
2 77
3 33
8 21
9 12
10 64
79
In the first sample, it takes at least 11 seconds to bring all passengers to floor 0. Here is how this could be done:
1. Move to floor 5: takes 2 seconds.
2. Pick up passenger 3.
3. Move to floor 3: takes 2 seconds.
4. Wait for passenger 2 to arrive: takes 4 seconds.
5. Pick up passenger 2.
6. Go to floor 2: takes 1 second.
7. Pick up passenger 1.
8. Go to floor 0: takes 2 seconds.
This gives a total of 2 + 2 + 4 + 1 + 2 = 11 seconds.
题意就是电梯接乘客,这个电梯只能从上往下走,给的数据是在第几层有乘客,乘客到达该层的时间,乘客上电梯的时间忽略不计,要求输出花费的最短时间是多少。
我的理解就是单独把某层的时间拿出来算一下,从该层到最底层花的时间+等待乘客的时间和总的层数花的时间比较一下,找出max,然后其他层也是这样,和上一组楼层的max比较一下。其实总的想一下,就是把楼层数+等待乘客的时间找出max,然后和总的楼层数比较一下就可以了。(最近好多题都用到这种思想了,不知道这种思想叫啥,但是感觉有时候挺好用的,就是有时用这种思路写题会T,超时了耶。。。)
代码:
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,m,f,t;
int maxx=-;
while(~scanf("%d%d",&n,&m)){
for(int i=;i<n;i++){
scanf("%d%d",&f,&t);
if(f+t>maxx)
maxx=max(f+t,maxx);
}
if(maxx<m)
printf("%d\n",m);
else
printf("%d\n",maxx);
}
return ;
}
Codeforces Round #336 (Div. 2)-608A.水题 608B.前缀和的更多相关文章
- A. Yellow Cards ( Codeforces Round #585 (Div. 2) 思维水题
---恢复内容开始--- output standard output The final match of the Berland Football Cup has been held recent ...
- Codeforces Round #345(Div. 2)-651A.水题 651B.。。。 651C.去重操作 真是让人头大
A. Joysticks time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- Codeforces Round #315 (Div. 2) B 水题强行set
B. Inventory time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- Codeforces Round #336 (Div. 2)B. Hamming Distance Sum 前缀和
B. Hamming Distance Sum 题目连接: http://www.codeforces.com/contest/608/problem/A Description Genos need ...
- Codeforces Round #336 (Div. 2) D. Zuma
Codeforces Round #336 (Div. 2) D. Zuma 题意:输入一个字符串:每次消去一个回文串,问最少消去的次数为多少? 思路:一般对于可以从中间操作的,一般看成是从头开始(因 ...
- Codeforces Round #609 (Div. 2)前五题题解
Codeforces Round #609 (Div. 2)前五题题解 补题补题…… C题写挂了好几个次,最后一题看了好久题解才懂……我太迟钝了…… 然后因为longlong调了半个小时…… A.Eq ...
- Codeforces Round #297 (Div. 2)B. Pasha and String 前缀和
Codeforces Round #297 (Div. 2)B. Pasha and String Time Limit: 2 Sec Memory Limit: 256 MBSubmit: xxx ...
- Educational Codeforces Round 7 B. The Time 水题
B. The Time 题目连接: http://www.codeforces.com/contest/622/problem/B Description You are given the curr ...
- Educational Codeforces Round 7 A. Infinite Sequence 水题
A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/622/problem/A Description Consider the ...
随机推荐
- go实例之函数
1.可变参数 示例代码如下: package main import "fmt" // Here's a function that will take an arbitrary ...
- ArcGIS 网络分析[2.1] 最短路径
最短路径求解 [如果看到此博客还没有网络数据集的,请参考第一章的内容,点击我,看目录] 最短路径,是什么最短?时间最短?距离最短?什么距离?路程距离? 考虑到拥堵问题,限速问题,换乘问题,在现实的最短 ...
- 模板引擎(smarty)知识点总结
首先我们必须知道使用smarty的流程 1.引入 2.实例化 3.配置 模板目录 编译目录 3.0版本 支持不存在的目录则新建 4.赋值 5.编译显示 某个模板文件(暗示需要哪 ...
- Docker(十一):Docker实战部署HTTPS的Tomcat站点
1.选择基础镜像 docker pull tomcat:7.0-jre8 2.生成HTTPS证书 keytool -genkey -alias tomcat -keyalg RSA -keystor ...
- 第六节 etc/passwd 、etc/shadow 、 useradd 、 groupadd
调优方法原理:禁用atime的修改来节省cpu和内存资源.命令:mount noatime disk 1.配置文件1. /etc/passwd文档结构:由":" 分隔成7个字段&q ...
- a标签实现一键拨号、发短信、发邮件、发起QQ会话
a标签href的妙用: <a href="tel:400-888-6633">拨打电话<a> <a href="sms:19956321 ...
- vim 当前用户显示行号
在 -/.vimrc 中添加 set nu 如果文件不存在可以直接新建这个文件 -表示当前用户的主目录
- 响应式布局—设备像素密度测试 (-webkit-min-device-pixel-ratio)
最近遇到这种头疼的问题,百思不得其解,不耻下问,悬梁刺股这些事情都做过之后,终于看到希望,于是攒见好就收,感觉整理分享给大家,希望有所帮助. 对手机分辨率和网页像素的初步认识是,是2倍的差别. 但 ...
- 《吸血鬼日记》(The Vampire Diaries)经典台词
Best quotes from The Vampire Diary 1. I will start fresh, be someone new. 1.我要重新开始,做不一样的自己. 2. It’s ...
- Java 测试驱动开发--“井字游戏” 游戏实战
TDD 介绍 TDD是测试驱动开发(Test-Driven Development)的英文简称,是敏捷开发中的一项核心实践和技术,也是一种设计方法论.TDD的原理是在开发功能代码之前,先编写单元测试用 ...