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

Sample test(s)
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.

题意:电梯最开始在最顶楼,里面载了0个人,给出下面n个人会在第几楼第几秒出现,让你计算 电梯从其实位置接到n个人 并且回到第0层楼 所需的最少时间

题解:  因为你必然经过每一层楼,我们找到接哪个人所需时间最多就好了,遍历一遍

//meek///#include<bits/stdc++.h>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include<iostream>
#include<bitset>
using namespace std ;
#define mem(a) memset(a,0,sizeof(a))
#define pb push_back
#define fi first
#define se second
#define MP make_pair
typedef long long ll; const int N = ;
const int inf = 0x3f3f3f3f;
const int MOD = ;
const double eps = 0.000001; int n,s;
struct ss {
int f,t,n,s;
}a[N];
int cmp (ss s1,ss s2) {
return s1.f>s2.f;
}
int main() {
scanf("%d%d",&n,&s);
int an=-;
for(int i=;i<=n;i++) {
scanf("%d%d",&a[i].f,&a[i].t);
an=max(an,a[i].f+max(a[i].t,s-a[i].f));
}
cout<<an<<endl;
return ;
}

代码

Codeforces Round #336 (Div. 2) A. Saitama Destroys Hotel 模拟的更多相关文章

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

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

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

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

  3. Codeforces Round #336 (Div. 2)【A.思维,暴力,B.字符串,暴搜,前缀和,C.暴力,D,区间dp,E,字符串,数学】

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

  4. Codeforces Round #336 (Div. 2)

    水 A - Saitama Destroys Hotel 简单的模拟,小贪心.其实只要求max (ans, t + f); #include <bits/stdc++.h> using n ...

  5. Codeforces Round #336 (Div. 2)-608A.水题 608B.前缀和

    A题和B题...   A. Saitama Destroys Hotel time limit per test 1 second memory limit per test 256 megabyte ...

  6. Codeforces Round #336 (Div. 2) A

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

  7. Codeforces Round #367 (Div. 2) B. Interesting drink (模拟)

    Interesting drink 题目链接: http://codeforces.com/contest/706/problem/B Description Vasiliy likes to res ...

  8. Codeforces Round #336 (Div. 2) C. Chain Reaction set维护dp

    C. Chain Reaction 题目连接: http://www.codeforces.com/contest/608/problem/C Description There are n beac ...

  9. Codeforces Round #336 (Div. 2)C. Chain Reaction DP

    C. Chain Reaction   There are n beacons located at distinct positions on a number line. The i-th bea ...

随机推荐

  1. iOS学习之Object-C语言字符串和数值

    一.使用苹果帮助文档      1.帮助文档的作用:帮助开发者快速了解系统类的功能.           1)苹果每次iOS版本的升级,都会添加或者更新大量的API,并提供相应的参考文档.       ...

  2. VS模板文件修改,自动生成注释

    VS的模板文件存放在IDE下的ItemTemplatesCache文件夹下 1.不同VS版本IDE文件夹路径个有不同,下面以VS2012为例,IDE文件夹路径如图:

  3. 20145120 《Java程序设计》第9周学习总结

    20145120 <Java程序设计>第9周学习总结 教材学习内容总结 JDBC希望程序能操作所有数据库 操作JDBC驱动有4种类型: JDBC-ODBC Bridge Driver Na ...

  4. CS小分队第一阶段冲刺站立会议(5月10日)

    昨日成果:完成了从excel表格导入名单,并且进行抽号的功能 遇到的困难: 1.Excel表格导入时由于版本不同,导致旧版本无法显示,后经修改初步解决 2.改程序无法在未安装office excel驱 ...

  5. C语言编写的随机产生四则运算测试题

    题目:编写一个四则运算测试题的程序,要求每道题都要随机产生 解题思路: 1.编写测试题,且为30道,就要用到循环函数,因此想到用for()函数 2.随机产生两个数,就想到用rand()函数. 注:1. ...

  6. Mac下安装及配置Eclipse

    1.安装Eclipse前先确认你的Mac上是否已安装java运行环境.进入终端,输入”java -version”,如果返回了java版本号则说明已安装,否则,请先安装java运行环境: 2.访问ec ...

  7. PCA算法

    本文出处:http://blog.csdn.net/xizhibei http://www.cnblogs.com/bourneli/p/3624073.html PrincipalComponent ...

  8. 【转】免装版tomcat注册成windows系统服务方法

    转自:http://blog.csdn.net/huiwenjie168/article/details/42267353 一.下载Tomcat Tomcat可以从http://tomcat.apac ...

  9. Window.document对象(1)

    1.Window.document对象 一.找到元素: docunment.getElementById("id"):根据id找,最多找一个:     var a =docunme ...

  10. MYbatis调试日记(三)

    如何在Mybatis中插入日期类型的数据 直接见代码: xml配置文件 java代码