BZOJ 2465: [中山市选2009]小球

难度在于读题

#include<cstdio>
#include<algorithm>
using namespace std;
int a[1000005];
struct node{
	int c,val;
}e[1000005];
bool cmp(node a,node b){
	return a.val>b.val;
}
int main(){
	while (1){
		int n,m;
		scanf("%d%d",&n,&m);
		if (n==0 && m==0) break;
		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",&e[i].c,&e[i].val);
		sort(e+1,e+m+1,cmp);
		int ans=0,ANS=0,top=1;
		for (int i=n; i>=1; i--){
			while (top<=m && !e[top].c) top++; 
			if (top<=m && a[i]<=e[top].val){
				e[top].c--;
				ans++;
				ANS+=a[i];
			}
		}
		printf("%d %d\n",ans,ANS);
	}
	return 0;
}

  

posted @ 2018-10-18 21:06  ~Silent  阅读(210)  评论(0编辑  收藏  举报
Live2D