Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register
欢迎参加IJCAI 2020麻将智能体竞赛,大奖等你拿!Welcome to IJCAI 2020 Mahjong AI competition with amazing prizes! | 北京大学《ACM/ICPC大学生程序设计竞赛训练》暑期课面向全球招生!

ac代码!

Posted by mc77xy at 2020-02-12 12:36:27 on Problem 2431
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
using namespace std;
int l,p,n;
pair<int,int>pa[10005];
bool cmp(pair<int,int> a,pair<int,int> b){
	return a.first<b.first;
}
void solve(){
	pa[n].first=l;
	pa[n].second=0;
	n++;
	priority_queue<int>que;
	int ans=0,pos=0,tank=p;
	for(int i=0;i<n;i++){
		int d=pa[i].first-pos;
		while(tank-d<0){
			if(que.empty()){
				puts("-1");
				return;
			}
			tank+=que.top();
			que.pop();
			ans++;
		}
		tank-=d;
		pos=pa[i].first;
		que.push(pa[i].second);
	}
	printf("%d\n",ans);
}
int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%d%d",&pa[i].first,&pa[i].second);
	scanf("%d%d",&l,&p);
	for(int i=0;i<n;i++)	pa[i].first=l-pa[i].first;
	sort(pa,pa+n,cmp);
	solve();
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator