CodeForces - 608A-Saitama Destroys Hotel(模拟)
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 sat 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.
Input
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.
Output
Print a single integer — the minimum amount of time in seconds needed to bring all the passengers to floor 0.
Examples
Input
3 7
2 1
3 8
5 2
Output
11
Input
5 10
2 77
3 33
8 21
9 12
10 64
Output
79
题解:模拟就好了,每次比较他的到达时间和电梯到达时间谁大,谁大就更新谁,最后加上最后一项的楼层数
代码:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
struct node {
int a,b;
} p[1005];
bool cmp(node x,node y) {
return x.a>y.a;
}
int main() {
int n,s;
cin>>n>>s;
for(int t=0; t<n; t++) {
scanf("%d%d",&p[t].a,&p[t].b);
}
sort(p,p+n,cmp);
int sum=max(s-p[0].a,p[0].b);
for(int t=1; t<n; t++) {
sum=max(sum+p[t-1].a-p[t].a,p[t].b);
}
cout<<sum+p[n-1].a<<endl;
return 0;
}
CodeForces - 608A-Saitama Destroys Hotel(模拟)的更多相关文章
- Codeforces Round #336 (Div. 2) A. Saitama Destroys Hotel 模拟
A. Saitama Destroys Hotel Saitama accidentally destroyed a hotel again. To repay the hotel company ...
- Codeforces Round #336 (Div. 2)A. Saitama Destroys Hotel 水题
A. Saitama Destroys Hotel 题目连接: http://www.codeforces.com/contest/608/problem/A Description Saitama ...
- Codeforces 608 A. Saitama Destroys Hotel
A. Saitama Destroys Hotel time limit per test 1 second memory limit per test 256 megabytes input ...
- Codefroces A. Saitama Destroys Hotel
A. Saitama Destroys Hotel time limit per test 1 second memory limit per test 256 megabytes input sta ...
- CodeForces.158A Next Round (水模拟)
CodeForces.158A Next Round (水模拟) 题意分析 校赛水题的英文版,坑点就是要求为正数. 代码总览 #include <iostream> #include &l ...
- Codeforces 747C:Servers(模拟)
http://codeforces.com/problemset/problem/747/C 题意:有n台机器,q个操作.每次操作从ti时间开始,需要ki台机器,花费di的时间.每次选择机器从小到大开 ...
- Codeforces 740A. Alyona and copybooks 模拟
A. Alyona and copybooks time limit per test: 1 second memory limit per test: 256 megabytes input: st ...
- Codeforces 716A Crazy Computer 【模拟】 (Codeforces Round #372 (Div. 2))
A. Crazy Computer time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- CodeForces 670 A. Holidays(模拟)
Description On the planet Mars a year lasts exactly n days (there are no leap years on Mars). But Ma ...
随机推荐
- html5--1.14 特殊符号的使用
html5--1.14 特殊符号的使用 学习要点: 实体的概念一个表格小实例 1.HTML 实体 在 HTML 中,某些字符是预留的. 在 HTML 中不能使用小于号(<)和大于号(&am ...
- PSPnet:Pyramid Scene Parsing Network——作者认为现有模型由于没有引入足够的上下文信息及不同感受野下的全局信息而存在分割出现错误的情景,于是,提出了使用global-scence-level的信息的pspnet
from:https://blog.csdn.net/bea_tree/article/details/56678560 2017年02月23日 19:28:25 阅读数:6094 首先声明,文末彩蛋 ...
- ActorModel 概念翻译
学习 skynet 时初次接触到 ActorModel 模型,始终觉得有必要从宏观上了解 ActorModel 的概念,所以以维基上这篇文章为参考,把文章中的部分内容翻译成中文,好让自己体会一下 Ac ...
- skynet实践(9)-随机数重复问题
最近在使用skynet的过程中,遇到需要为玩家的每次请求产生一个随机序列的场景.简化如下: main.lua中每隔1S便发出一次随机数请求: local skynet = require " ...
- python下setuptools安装
python下的setuptools带有一个easy_install的工具,在安装python的每三方模块.工具时很有用,也很方便.安装setuptools前先安装pip,请参见<pytho ...
- zjoi2015d1题解
闲来无事做了丽洁姐姐的题 t1给一棵树 每个点有点权 每次修改点权 修改后询问每个点到树的带权重心的带权距离是多少 每个点度数不超过20 很显然的一个点分树... 我们记一下 每个点的子树中的所有点到 ...
- nginx开发笔记_ngx_hash源码解析
ngx_hash源码解析 ngx_hash是nginx中的hash表结构,具有以下特点: 静态结构,hash表创建后无法动态添加/删除KV. 采用连续存储方式解决碰撞问题.即出现碰撞的KV存放在连续地 ...
- Mysql MMM 高可用
一.Mysql MMM 高可用概况: mmm_mond 负责所有的监控工作的监控守护进程,决定节点的移除等: mmm_agentd 运行在mysql服务器上的代理守护进程,通过简单远程服务集提供给 ...
- js能否实现截图,截图之后的图片数据再下载到本地?
https://www.zhihu.com/question/20763177 http://www.cnblogs.com/yanweidie/p/5203943.html
- CF-845B
B. Luba And The Ticket time limit per test 2 seconds memory limit per test 256 megabytes input stand ...