HDU - 1789貪心
阿新 • • 發佈:2018-12-28
#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; }