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

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