CodeForces 608A Saitama Destroys Hotel

来源:互联网 发布:编程有几种语言 编辑:程序博客网 时间:2024/06/05 05:59
A - Saitama Destroys Hotel
Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
Submit Status Practice CodeForces 608A

Description

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 tos 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 ≤ 1001 ≤ 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 ≤ s1 ≤ 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 Input

Input
3 72 13 85 2
Output
11
Input
5 102 773 338 219 1210 64
Output
79

Hint

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.


FAQ | About Virtual Judge | Forum | Discuss | Open Source Project
题意: 一共有n个人 ,  s层高的大楼,电梯起初在顶层S;每个人所在楼层和到达电梯口的时间可能不同,求把所有人 带到底楼(就是1层),所用的最小时间~
思路::: 一开始 我认为谁先到楼梯口 就去接谁,可后来发现这是错的~
应该直接是 从顶楼开始往一楼接人 电梯只降不升,如果在该层的人还没来 就等到他来,原因是因为:就算你先下去接先到的人,但是你还是要返回来接高楼层的人,如果返回用的时间太大 大于高楼层人到达楼梯口时间 就错了~~~
代码:
#include<iostream>#include<cstdio>#include<cmath>#include<queue>#include<algorithm>#include<cstring>#include<cstdlib>#define max(a,b)(a>b?a:b)#define min(a,b)(a<b?a:b)#define INF 999999999using namespace std;typedef long long ll;struct node{    int f;    int t;};bool cmp(node a,node b){    return a.f>b.f;}int main(){    int n,s,i;    struct node p[110];    while(scanf("%d%d",&n,&s)!=EOF)    {        for(i=1;i<=n;i++)            scanf("%d%d",&p[i].f,&p[i].t);        sort(p+1,p+n+1,cmp);        int ans=0;        p[0].f=s;        for(i=1;i<=n;i++)        {            ans=ans+abs(p[i-1].f-p[i].f);            if(ans<p[i].t)               ans=p[i].t;        }        printf("%d\n",ans+p[n].f);    }    return 0;}

0 0
原创粉丝点击