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 ...
随机推荐
- 获取url的参数
function getPrams () { var url, urlPrams, urlPramsArr=[], item=[], prams={}; url = location.href; if ...
- tensorflow 实现逻辑回归——原以为TensorFlow不擅长做线性回归或者逻辑回归,原来是这么简单哇!
实现的是预测 低 出生 体重 的 概率.尼克·麦克卢尔(Nick McClure). TensorFlow机器学习实战指南 (智能系统与技术丛书) (Kindle 位置 1060-1061). Kin ...
- 菜鸟快速自学java00之变量类型
---恢复内容开始--- 菜鸟快速自学java00之变量类型 一.诉苦 自己成为了Java中的一只菜鸟,而且已经菜了好多天了,我为什么会这么菜?归根结底,还是觉得自己在累计知识的同时,没有做好笔记,导 ...
- listen 77
Your Dog Wants YOUR Food Does your puppy turn his nose up at his own chow—because he wants some of w ...
- BZOJ - 2553 :禁忌(AC自动机+贪心+奇怪的矩阵)
Magic Land上的人们总是提起那个传说:他们的祖先John在那个东方岛屿帮助Koishi与其姐姐Satori最终战平.而后,Koishi恢复了读心的能力…… 如今,在John已经成为传说的时代, ...
- 洛谷P1584 魔杖
题目描述 Smart在春游时意外地得到了一种好东西——一种非常珍贵的树枝.这些树枝可以用来做优质的魔杖! 选择怎样的切割方式来制作魔杖非常重要,关键问题是——一把魔杖既不能太长.又不能太短,且制作出来 ...
- Microsoft SQL Server 数据库
1. master 数据库 master 数据库记录 SQL Server 系统的所有系统级别信息.它记录所有的登录帐户和系统配置设置.master 数据库是这样一个数据库,它记录所有其它的数据库,其 ...
- json格式化插件
插件名称:JSON-Handle 下载地址: http://jsonhandle.sinaapp.com/
- thymeleaf控制view的返回格式
package com.ailk.dd1.jike.web.config; import nz.net.ultraq.thymeleaf.LayoutDialect; import org.sprin ...
- Process打开文件
引用:using System.Diagnostics; 打开文件夹: System.Diagnostics.Process.Start(FilePath); 打开文件夹中某个文件: System.D ...