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 <iostream> #include <stdio.h> #include <algorithm> #include <string.h> using namespace std; #define M 1000 #define N 100 struct node{ int time,s; }dp[M]; bool cmp(node x,node y) { if(x.s==y.s) return x.time<y.time; return x.s>y.s; } int map[M]; int main() { int i,j,n,m; cin>>m; while(m--) { cin>>n; int cur=0; memset(map,0,sizeof(0)); for(i=0;i<n;i++) cin>>dp[i].time; for(i=0;i<n;i++) cin>>dp[i].s; sort(dp,dp+n,cmp); memset(map,0,sizeof(map)); for(i=0;i<n;i++) { for(j=dp[i].time;j>0;j--) { if(!map[j]) {map[j]=1;break;} } if(j==0) cur+=dp[i].s; } cout<<cur<<endl; } return 0; }
HDU 1789 Doing Homework again (贪心),布布扣,bubuko.com
HDU 1789 Doing Homework again (贪心)
原文地址:http://blog.csdn.net/qq2256420822/article/details/38292799