1. 程式人生 > >HDU - 1789貪心

HDU - 1789貪心

#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
bool f[1005];
struct node{
	int deadlines,score;
	bool operator < (const node a) const{
		return score>a.score;	
	}
}a[1005];
int main(){
	int t,n,sum,j;
	cin>>t;
	while(t--){
		sum=0;
		cin>>n;
		memset(a,0,sizeof(a));
		memset(f,0,sizeof(f));
		for(int i=0;i<n;i++){
			cin>>a[i].deadlines;
		}
		for(int i=0;i<n;i++){
			cin>>a[i].score;
		}
		sort(a,a+n);
		for(int i=0;i<n;i++){
			for(j=a[i].deadlines;j>0;j--){
			if(!f[j]){
				f[j]=1;
				break;
			}
			}
			if(j==0){
				sum+=a[i].score;
			}
		}
		cout<<sum<<endl;	
	}
	return 0;
}