标签:struct 51nod ons color std can pen empty lap
【算法】贪心
#include<cstdio> #include<algorithm> #include<cstring> #include<queue> using namespace std; const int maxn=50010; struct cyc{int num,value;}b[maxn]; int n,m,a[maxn]; long long ans=0; priority_queue<int,vector<int>,greater<int> >q; bool cmp(cyc a,cyc b) {return a.num<b.num;} int main() { scanf("%d%d",&n,&m); for(int i=1;i<=n;i++)scanf("%d",&a[i]); sort(a+1,a+n+1); for(int i=1;i<=m;i++)scanf("%d%d",&b[i].num,&b[i].value); sort(b+1,b+m+1,cmp); int now=m+1; bool ok=1; for(int i=n;i>=1;i--) { for(int j=now-1;j>=1;j--) { if(b[j].num>=a[i]){now=j;q.push(b[j].value);} else break; } if(q.empty()){ok=0;break;} ans+=q.top(); q.pop(); } if(!ok)printf("No Solution"); else printf("%lld",ans); return 0; }
标签:struct 51nod ons color std can pen empty lap
原文地址:http://www.cnblogs.com/onioncyc/p/7056253.html