codeforces #336 div 2 A. Saitama Destroys Hotel
http://codeforces.com/contest/608/problem/A 题意:一个电梯,从s到0层,单项,给出n个人,每个人在某时间出现在某层,问要花多长时间把所有人运到0。初始电梯在s,每下一层话费时间1,上来人不花时间。 思路:由于电梯只能是单项,那么到达某一层的时候,一定要等到把这层中最晚来的那个接走。所以排序的时候按照楼层高到低为第一关键字,等待时间长到短为第二关键字。对于同一楼层出现的,只考虑第一个即可,也就是最后出现的。需要注意的是最后接完最后一个人以后把电梯运行道0层。
/* ***********************************************
Author :111qqz
Created Time :2015年12月24日 星期四 00时32分24秒
File Name :code/cf/#336/A.cpp
************************************************ */
1#include <cstdio>
2#include <cstring>
3#include <iostream>
4#include <algorithm>
5#include <vector>
6#include <queue>
7#include <set>
8#include <map>
9#include <string>
10#include <cmath>
11#include <cstdlib>
12#include <ctime>
13#define fst first
14#define sec second
15#define lson l,m,rt<<1
16#define rson m+1,r,rt<<1|1
17#define ms(a,x) memset(a,x,sizeof(a))
18typedef long long LL;
19#define pi pair < int ,int >
20#define MP make_pair
1using namespace std;
2const double eps = 1E-8;
3const int dx4[4]={1,0,0,-1};
4const int dy4[4]={0,-1,1,0};
5const int inf = 0x3f3f3f3f;
6const int N=105;
7int n;
8int s;
9struct node
10{
11 int f,t;
1 bool operator <(node b)const
2 {
3 if (f>b.f) return true;
4 if (f==b.f&&t>b.t) return true;
5 return false;
6 }
7}q[N];
8int main()
9{
10 #ifndef ONLINE_JUDGE
11 freopen("code/in.txt","r",stdin);
12 #endif
13 cin>>n>>s;
14 for ( int i = 1 ; i<= n ;i++) cin>>q[i].f>>q[i].t;
1 sort(q+1,q+n+1);
2 int cur = s;
3 int t = 0 ;
4 q[0].f = -1;
5// for ( int i = 1 ; i <= n ; i++) cout<<q[i].f<<" "<<q[i].t<<endl;
6 for ( int i = 1 ; i <= n ; i++)
7 {
8 if (q[i].f==q[i-1].f) continue;
9 t+=cur-q[i].f;
10 // cout<<"t:"<<t<<" ";
11 cur = q[i].f;
12 if (t<q[i].t)
13 {
14 t = q[i].t;
15 }
16 // cout<<"t2:"<<t<<endl;
17 }
18 t+=q[n].f;
19 cout<<t<<endl;
1 #ifndef ONLINE_JUDGE
2 fclose(stdin);
3 #endif
4 return 0;
5}