51NOD -1191消灭兔子

题目链接:51NOD -1191消灭兔子


显然,我们从小到大枚举兔子。

然后贪心从可以选的当中选最小值即可。用堆维护。


AC代码:

#pragma GCC optimize("-Ofast","-funroll-all-loops")
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=5e4+10;
int n,m,b[N],res,pos;
struct node{int d,p;}t[N];
int cmp(node a,node b){return a.d>b.d;}
priority_queue<int,vector<int>,greater<int> > q;
signed main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++)	scanf("%lld",&b[i]);
	for(int i=1;i<=m;i++)	scanf("%lld %lld",&t[i].d,&t[i].p);
	sort(b+1,b+1+n);	sort(t+1,t+1+m,cmp);	pos=1;
	for(int i=n;i>=1;i--){
		while(pos<=m&&t[pos].d>=b[i])	q.push(t[pos].p),pos++;
		if(q.empty())	return puts("No Solution"),0;
		res+=q.top();	q.pop();
	}
	cout<<res;
	return 0;
}
发布了809 篇原创文章 · 获赞 246 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/weixin_43826249/article/details/105256589
今日推荐