3 3 3 3 3 10 5 1 3 1 3 1 6 2 3 7 1 4 6 4 2 4 3 3 2 1 7 6 5 4
0 3 5
#include<cstdio> #include<map> #include<iostream> #include<algorithm> using namespace std; map<int,bool>mp; struct homework { int deadline,score; }home[1000+10]; bool cmp(homework a,homework b) { if(a.score==b.score) return a.deadline<b.deadline; else return a.score>b.score; } int main() { int n,ans,l,t; scanf("%d",&t); while(t--) { scanf("%d",&n); ans=0; for(int i=1;i<=n;i++) { scanf("%d",&home[i].deadline); mp[i]=false; } for(int i=1;i<=n;i++) scanf("%d",&home[i].score); sort(home+1,home+1+n,cmp); for(int i=1;i<=n;i++) { for(l=home[i].deadline;l>=1;l--) { if(!mp[l]) { mp[l]=true; break; } } if(l<1) ans=ans+home[i].score; } printf("%d\n",ans); } return 0; }
hdu1789Doing Homework again(贪心),布布扣,bubuko.com
hdu1789Doing Homework again(贪心)
原文:http://blog.csdn.net/u014303647/article/details/38342241