比赛 20140414 评测结果 AWTTTTTTTT
题目名称 登机 最终得分 10
用户昵称 cstdio 运行时间 8.288 s
代码语言 C++ 内存使用 3.36 MiB
提交时间 2014-04-14 11:06:45
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#include<map>
#include<deque>
using namespace std;
const int SIZEN=200010;
int N;
int S[SIZEN]={0},T[SIZEN]={0};
int lefttime[SIZEN]={0},now[SIZEN]={0};
int boardnum=0,enternum=0;
void step(void){
	//for(int i=1;i<=N;i++) cout<<now[i]<<" ";cout<<endl;
	for(int i=enternum+1;i>=1;i--){
		if(now[i]==0){
			if(now[i-1]&&S[now[i-1]]!=i-1){//走一步
				now[i]=now[i-1];
				now[i-1]=0;
				if(now[i]&&i==S[now[i]]){
					lefttime[now[i]]=T[now[i]];
				}
			}
		}
		else{
			lefttime[now[i]]--;
			if(lefttime[now[i]]==0){
				now[i]=0;
				boardnum++;
			}
		}
	}
	if(now[0]==0){
		enternum++;
		now[0]=N-enternum+1;
		//now[0]=++enternum;
	}
}
void work(void){
	int ans=0;
	while(boardnum<N){
		step();
		ans++;
		//cout<<ans<<endl;
		//for(int i=1;i<=N;i++){cout<<now[i]<<" ";}cout<<endl;
	}
	printf("%d\n",ans-1);
}
void read(void){
	scanf("%d",&N);
	for(int i=1;i<=N;i++) scanf("%d%d",&S[i],&T[i]);
}
int main(){
	freopen("boarding.in","r",stdin);
	freopen("boarding.out","w",stdout);
	read();
	work();
	return 0;
}