• 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;
    }
  • 相关阅读:
    angular 按下回车键触发事件
    vue 父组件与子组件的通信
    最近在开发一个文章聚合的工具
    Martinjingyu的开发环境
    个推push数据统计(爬虫)
    基于redis的订单号生成方案
    电商平台--Mysql主从搭建(2)
    Mysql主从搭建(1)
    mysql物理级别热备脚本
    外键查询及删除
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5075215.html
Copyright © 2020-2023  润新知