您的位置:首页 > 大数据 > 人工智能

CodeForces 608 A. Saitama Destroys Hotel(水~)

2016-02-29 21:37 453 查看
Description

一个s层的大楼有一个只能下的电梯,电梯初始在第s层,现在有n个人在ti时刻到达第fi层电梯处乘电梯到第0层,问电梯将这些人送到0层需要花费多少时间

Input

第一行两个整数n和s分别表示人数和大楼层数,之后n行每行两个整数fi和ti表示第i个人在ti时到达第fi层电梯处乘电梯

(1<=n<=100,1<=s<=1000,1<=fi<=s,1<=ti<=1000)

Output

输出将这n个人送到第0层最少花费多少时间

Sample Input

3 7

2 1

3 8

5 2

Sample Output

11

Solution

水题

Code

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
#define maxn 1111
int n,s,a[maxn],f,t;
int main()
{
while(~scanf("%d%d",&n,&s))
{
memset(a,0,sizeof(a));
for(int i=0;i<n;i++)
{
scanf("%d%d",&f,&t);
a[f]=max(a[f],t);
}
int ans=0,time=0;
for(int i=s;i>0;i--)
{
if(a[i]>=time)ans+=a[i]-time;
time=++ans;
}
printf("%d\n",ans);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: