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

A. Saitama Destroys Hotel

题目连接:

http://www.codeforces.com/contest/608/problem/A

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

3 7

2 1

3 8

5 2

Sample Output

11

Hint

题意

有一个电梯,一开始停靠在第s层,这个电梯很奇怪,只能往下走

有n个人,他们会在第t秒出现在第f层

电梯每下一层需要1s,问你把这些人全部送到0层,最少需要多少秒

题解:

暴力扫一遍就好了,暴力扫每一层,这个电梯最少多少秒到达这一层就好了

每一层到达的时间,由上一层决定

有点像dp

代码

#include<bits/stdc++.h>
using namespace std;
#define maxn 1005
int a[maxn];

int main()
{
    int n,s;scanf("%d%d",&n,&s);
    for(int i=1;i<=n;i++)
    {
        int x,t;scanf("%d%d",&x,&t);
        a[x]=max(t,a[x]);
    }
    int x,y;
    int ans=0;
    for(int i=s;i>=0;i--)
    {
        ans = max(ans,a[i]);
        ans++;
    }
    cout<<ans-1<<endl;
}

转载于:https://www.cnblogs.com/qscqesze/p/5075215.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值