P2949 [USACO09OPEN]Work Scheduling G

Aimee

很水的题目

很简单的反悔贪心,能干就干,干不了就把最小的扔掉

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<queue>
#define int long long
using namespace std;
priority_queue <int> q;
int Aimee;
int n;
struct wor{
	int ti;
	int mo;
} th[100001];
int read(){
	int f=1,ans=0;
	char c;
	c=getchar();
	while(c!='-'&&(c<'0'||c>'9')){
		c=getchar();
	}
	if(c=='-'){
		f=-1;
		c='0';
	}
	while(c>='0'&&c<='9'){
		ans=(ans<<1)+(ans<<3)+c-'0';
		c=getchar();
	}
	return ans*f;
}
bool cmp( wor x,wor y){
	return x.ti<y.ti;
}
signed main(){
	n=read();
	for(int i=1;i<=n;++i){
		th[i].ti=read();
		th[i].mo=read(); 
	}
	sort(th+1,th+n+1,cmp);
	for(int i=1;i<=n;++i){
		q.push(-th[i].mo);
		Aimee+=th[i].mo;
		if(q.size()>th[i].ti){
			Aimee+=q.top();
			q.pop();
		}
	}
	printf("%lld",Aimee); 
	return 0;
} 
posted @ 2020-11-05 21:08  Simex  阅读(61)  评论(0编辑  收藏  举报