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. jQuery Tab选项卡切换代码

    jQuery Tab选项卡切换代码是一款简单的jquery tab选项卡切换网页特效代码样式,可以修改tab选项卡相关样式. 代码下载:http://www.huiyi8.com/sc/10863.h ...

  2. IDEAL葵花宝典:java代码开发规范插件 p3c

    前言: P3C插件 是阿里巴巴p3c项目组进行研发.这个项目组是阿里巴巴开发爱好者自发组织形成的虚拟项目组,根据<阿里巴巴Java开发规范>转化而成的自动化插件,并且实现了部分自动编程. ...

  3. NOIP 2014【斗地主】

    这真是道大火题. 因为保证数据随机,所以开始很多人直接用搜索 + 贪心水过去了,后来,为了遏制骗分这种不良风气的传播,各大 OJ 相继推出了斗地主加强版-- 正解: 先爆搜顺子,枚举打或不打,打多少张 ...

  4. EmbarassedBirds全体开发人员落泪

    Github (李昆乘,赖展飞) 现阶段还在开发后期,API调试过程中. 本周无法上线. 全体开发人员留下眼泪. 贴上几个功能图, 给大家尝尝鲜吧! 现阶段仍在API调试 因为队员李昆乘经常出去玩没有 ...

  5. ACM学习历程—HDU5265 pog loves szh II(策略 && 贪心 && 排序)

    Description Pog and Szh are playing games.There is a sequence with $n$ numbers, Pog will choose a nu ...

  6. navicat 关于orcale新建表空间,用户和权限分配

    图文教程,直观, 上面连接数据库 下面创建表空间 建表空间的设置 表空间名的设置 新建用户 填写用户名,选择默认表空间 成员属性德设置,这里因为是自己用,所以选择最大权限,其他的权限这是需要专业的了 ...

  7. AR/VR-AR:AR

    ylbtech-AR/VR-AR:AR 增强现实技术(Augmented Reality,简称 AR),是一种实时地计算摄影机影像的位置及角度并加上相应图像.视频.3D模型的技术,这种技术的目标是在屏 ...

  8. ACM实用C语言函数

    函数名: abs 功 能: 求整数的绝对值 用 法: int abs(int i); 程序例: #include <stdio.h> #include <math.h> int ...

  9. 02_SQliteOpenHelper介绍&oncreate方法介绍

    file:///D:/BaiduNetdiskDownload/adt-bundle-windows-x86_64_20140101/adt-bundle-windows-x86_64_2014010 ...

  10. 虚拟机中的Linux安装VMware&nbsp;Tools

    虚拟机中的Linux安装VMware Tools Tools" TITLE="虚拟机中的Linux安装VMware Tools" /> Tools" TI ...