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. 公牛与状压dp

    T1 疾病管理 裸得不能再裸的状压dp 不过数据范围骗人 考试时k==0的点没过 我也很无奈呀qwq #include<iostream> #include<cstdio> # ...

  2. NOI 2009 诗人小G

    题目描述 Description 小G是一个出色的诗人,经常作诗自娱自乐.但是,他一直被一件事情所困扰,那就是诗的排版问题. 一首诗包含了若干个句子,对于一些连续的短句,可以将它们用空格隔开并放在一行 ...

  3. php-自动过滤、自动填充、自动验证

    最近又学到了一些新技巧,和大家分享下. 第一.当一个表单有很大内容时,我们在表单处理页面接收这些表单的值的时候就会重复 接收,于是就有了自动过滤的解决之法(核心就是把数据表里需要的字段接收) 首先:我 ...

  4. 解决mysql漏洞 Oracle MySQL Server远程安全漏洞(CVE-2015-0411)

    有时候会检测到服务器有很多漏洞,而大部分漏洞都是由于服务的版本过低的原因,因为官网出现漏洞就会发布新版本来修复这个漏洞,所以一般情况下,我们只需要对相应的软件包进行升级到安全版本即可. 通过查阅官网信 ...

  5. 部署github开源软件遇到的问题

    jdk1.8源版本不一样: 将语言级别改为8,所有的jdk都配置为1.8 2. 遇到一些解析错误 应该是tomcat的jdk版本和项目的jdk版本不一样

  6. Git详解之三:Git分支

    Git 分支 几乎每一种版本控制系统都以某种形式支持分支.使用分支意味着你可以从开发主线上分离开来,然后在不影响主线的同时继续工作.在很多版本控制系统中,这是个昂贵的过程,常常需要创建一个源代码目录的 ...

  7. 中文代码示例之Vuejs入门教程(一)

    原址: https://zhuanlan.zhihu.com/p/30917346 为了检验中文命名在主流框架中的支持程度, 在vuejs官方入门教程第一部分的示例代码中尽量使用了中文命名. 所有演示 ...

  8. Linux如何让进程在后台运行的三种方法详解

    问题分析: 我们知道,当用户注销(logout)或者网络断开时,终端会收到 HUP(hangup)信号从而关闭其所有子进程.因此,我们的解决办法就有两种途径:要么让进程忽略 HUP 信号,要么让进程运 ...

  9. python实现散列表的直接寻址法

    散列表(Hash table,也叫哈希表),是根据键(Key)而直接访问在内存存储位置的数据结构.也就是说,它通过计算一个关于键值的函数, 将所需查询的数据映射到表中一个位置来访问记录,这加快了查找速 ...

  10. mysql加锁读

    Locking Reads 在同一个事务中,如果你先查询数据,随后对相关数据进行插入或修改,那么在标准的SLELECT中不会给出足够的保护.在你查询期间另一个事务可以更新或者删除相同的行.InnoDB ...