美文网首页
CodeFoeces-608A

CodeFoeces-608A

作者: ss5smi | 来源:发表于2018-02-13 19:56 被阅读0次

    题目

    原题链接:A. Saitama Destroys Hotel

    题意

    有一栋s层的楼,从顶楼往下走,有n个人要成电梯,给出每个人所在的楼层和到达时间。问将所有人带到底层要多久。

    代码

    #include<bits/stdc++.h>
    using namespace std;
    struct node{
        int f,t;
    }p[110];
    bool cmp(node a,node b){
        if(a.f==b.f) return a.t<b.t;
        return a.f>b.f;
    }
    int main() {
        int n,s;
        cin>>n>>s;
        for(int i=0; i<n; i++) {
            cin>>p[i].f>>p[i].t;
        }
        sort(p,p+n,cmp);
        int ans=0,t=s;
        for(int i=0;i<n;i++){
            ans+=t-p[i].f;
            t=p[i].f;
            int tmp=p[i].t-ans;
            ans+=tmp>0?tmp:0;
    //      printf("floor:%d time:%d\n",t,ans);
        }
        ans+=t;
        cout<<ans;
        return 0;
    }
    

    相关文章

      网友评论

          本文标题:CodeFoeces-608A

          本文链接:https://www.haomeiwen.com/subject/nsajtftx.html