time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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.

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
Note

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.前缀和的更多相关文章

  1. A. Yellow Cards ( Codeforces Round #585 (Div. 2) 思维水题

    ---恢复内容开始--- output standard output The final match of the Berland Football Cup has been held recent ...

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

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

  4. Codeforces Round #336 (Div. 2)B. Hamming Distance Sum 前缀和

    B. Hamming Distance Sum 题目连接: http://www.codeforces.com/contest/608/problem/A Description Genos need ...

  5. Codeforces Round #336 (Div. 2) D. Zuma

    Codeforces Round #336 (Div. 2) D. Zuma 题意:输入一个字符串:每次消去一个回文串,问最少消去的次数为多少? 思路:一般对于可以从中间操作的,一般看成是从头开始(因 ...

  6. Codeforces Round #609 (Div. 2)前五题题解

    Codeforces Round #609 (Div. 2)前五题题解 补题补题…… C题写挂了好几个次,最后一题看了好久题解才懂……我太迟钝了…… 然后因为longlong调了半个小时…… A.Eq ...

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

  8. Educational Codeforces Round 7 B. The Time 水题

    B. The Time 题目连接: http://www.codeforces.com/contest/622/problem/B Description You are given the curr ...

  9. Educational Codeforces Round 7 A. Infinite Sequence 水题

    A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/622/problem/A Description Consider the ...

随机推荐

  1. UITextFiled的输入框改成一条下划线

    在一些程序的界面中,它们的编辑框是一条线,而UITextFiled本身并没有这种style,所有需要我们自己设置.方法还是挺多的 第一种 , (1).我们可以声明一个类继承与UITextFiled ( ...

  2. sublime学习笔记

    学习课程地址:快乐的sublime编辑器_sublime编辑器使用 另可参考笔记地址:http://c.haoduoshipin.com/happysublime/ PS:博主的一些文章地址:http ...

  3. UVALive 4850 Installations

    题目大意:有若干个任务,每个任务耗时si,期限为di,同一时间只能做一个任务.对于一个任务,惩罚值为max(0,完成时间-期限).问怎么安排,使(最大惩罚值+次大惩罚值)最小,O(n^2). 如果没有 ...

  4. BZOJ1036 (其实这只是一份板子)

    我说我是不是完蛋了啊... ...昨天考试线段树写错,调了好久才调回来:今天做这道树链剖分辣鸡操作题,TM写错了4个地方!先是建树为了省常数打了一个build结果初值赋错了,然后又是线段树!getma ...

  5. 编译Twitter的Heron时一直报错“heron/bazel_configure.py", line 25, in <module> import semver ImportError: No module named semver”如何处理。

    今天编译heron的时候,从官方git到的源码bazel_configure的时候一直报错如下: Traceback (most recent call last): File , in <mo ...

  6. Linux下创建root权限的账号osadmin

    创建root权限的账号osadmin 命令为: useradd -u 0 -o -g root -G root -d /home/osadmin osadmin 创建成功后验证效果: id osadm ...

  7. Q:算法(第四版)—第一章

    1.1.14:编写一个静态方法lg(),接受一个整型参数N,返回不大于log2N的最大整数(ps:不使用Math库) 分析: 利用将公式k=log2N转化为N=2k的原理,不断的逼近其输入的值N,当N ...

  8. Mysql使用alias 防止对数据的误操作

    在我们操作数据库的时候,尤其是执行,update,delete操作的时候,都存在着误操作的风险,今天发现一种方法,能避免这一问题,就是使用Mysql的alias . 1.查看Mysql帮助 #mysq ...

  9. 关于md5的使用方法

    本周工作,学习中用到了,md5. 在我们需要用到md5密码的时候,可以使用: System.Web.Security.FormsAuthentication.HashPasswordForStorin ...

  10. PHP中引入文件的四种方式及区别

    文件加载语句:include,require,include_once,require_once include,require: require函数通常放在 PHP 程序的最前面,PHP 程序在执行 ...