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(模拟)的更多相关文章

  1. Codeforces Round #336 (Div. 2) A. Saitama Destroys Hotel 模拟

    A. Saitama Destroys Hotel   Saitama accidentally destroyed a hotel again. To repay the hotel company ...

  2. Codeforces Round #336 (Div. 2)A. Saitama Destroys Hotel 水题

    A. Saitama Destroys Hotel 题目连接: http://www.codeforces.com/contest/608/problem/A Description Saitama ...

  3. Codeforces 608 A. Saitama Destroys Hotel

      A. Saitama Destroys Hotel   time limit per test 1 second memory limit per test 256 megabytes input ...

  4. Codefroces A. Saitama Destroys Hotel

    A. Saitama Destroys Hotel time limit per test 1 second memory limit per test 256 megabytes input sta ...

  5. CodeForces.158A Next Round (水模拟)

    CodeForces.158A Next Round (水模拟) 题意分析 校赛水题的英文版,坑点就是要求为正数. 代码总览 #include <iostream> #include &l ...

  6. Codeforces 747C:Servers(模拟)

    http://codeforces.com/problemset/problem/747/C 题意:有n台机器,q个操作.每次操作从ti时间开始,需要ki台机器,花费di的时间.每次选择机器从小到大开 ...

  7. Codeforces 740A. Alyona and copybooks 模拟

    A. Alyona and copybooks time limit per test: 1 second memory limit per test: 256 megabytes input: st ...

  8. 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 ...

  9. CodeForces 670 A. Holidays(模拟)

    Description On the planet Mars a year lasts exactly n days (there are no leap years on Mars). But Ma ...

随机推荐

  1. listen 61

    Multiple Stresses Killed Snail Memory Stress sucks. It can affect your body and mind. Previous resea ...

  2. linux命令学习笔记(23):Linux 目录结构

    对于每一个Linux学习者来说,了解Linux文件系统的目录结构,是学好Linux的至关重要的一步.,深入了解linux文件 目录结构的标准和每个目录的详细功能,对于我们用好linux系统只管重要,下 ...

  3. 「LOJ#10036」「一本通 2.1 练习 2」Seek the Name, Seek the Fame (Hash

    题目描述 原题来自:POJ 2752 给定若干字符串(这些字符串总长 ≤4×105 \le 4\times 10^5 ≤4×105),在每个字符串中求出所有既是前缀又是后缀的子串长度. 例如:abab ...

  4. bzoj 3230 相似子串 —— 后缀数组+二分

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3230 先算出每个后缀贡献子串的区间: 然后前缀LCP直接查询,后缀LCP二分长度,查询即可: ...

  5. strlen("汉字")的值是多少

    转自:http://blog.csdn.net/gogor/article/details/4470775 strlen("汉字")的值是多少? 这个问题的答案与系统所采用的字符编 ...

  6. vim编辑器最常用按键说明

    n代表数字,words代表字符串 1.设置行号:输入 :set nu 2.跳到某行: 输入 nG. 首行1G,尾行G 3.向下删除连续的n行:先跳到要删除的某行,然后输入: ndd 4.向后删除某行的 ...

  7. Session与Cookie(1)

    Session session是一种位于服务端,用于存储一个会话(指打开浏览器访问某个域名,及其下面的资源,然后关掉浏览器的过程)中所需的配置信息.也就是在一个会话中,只存在一个session.对于J ...

  8. [xdoj1227]Godv的数列(crt+lucas)

    解题关键:1001=7*11*13,模数非常小,直接暴力lucas.递归次数几乎为很小的常数.最后用中国剩余定理组合一下即可. 模数很小时,一定记住lucas定理的作用 http://acm.xidi ...

  9. Unity3d笔记

    当变量重命名后,已序列化保存的值会丢失,如果希望继续保留其数值,可使用FormerlySerializedAs,如下代码所示: [UnityEngine.Serialization.FormerlyS ...

  10. qpython 读入数据问题: EOF error with input / raw_input

    直接使用input会报错 EOF error with input / raw_input 原因是在qpy里console mode 命令行模式不是完全和pc上的命令行一致,所以input和raw_i ...