现在的位置: 首页 > 综合 > 正文

1572: [Usaco2009 Open]工作安排Job

2018年01月13日 ⁄ 综合 ⁄ 共 727字 ⁄ 字号 评论关闭
#include<functional>
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<queue>
using namespace std;
inline int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
inline bool cmp(pair<int,int> a,pair<int,int> b){
	return a.second<b.second;
}
int n,last;
long long ans;
priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > heap;
pair<int,int> w[100001];
int main(){
	n=read();
	for(int i=1;i<=n;i++){
		int d=read(),p=read();
		w[i]=make_pair(p,d);
	}
	sort(w+1,w+n+1,cmp);
	for(int i=1;i<=n;i++){
		heap.push(w[i]);ans+=(long long)w[i].first;last++;
		if(last>w[i].second)ans-=(long long)heap.top().first,last--,heap.pop();
	}
	cout<<ans<<endl;
	return 0;
}

抱歉!评论已关闭.