Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Every teacher gives him a deadline of handing in the homework. If Ignatius hands in the homework after the deadline, the teacher will reduce his score of the final test. And now we assume that doing everyone homework always takes one day. So Ignatius wants you to help him to arrange the order of doing homework to minimize the reduced score.
题意:
每个功课都要花一天时间做,每门功课都有截止时间,如果超过截止时间,该门课的分就拿不到了,你的任务是计算他至少要扣掉几分。
输入:
t组样例,
每组第一行一个 n 代表有几门课,(1<=n<=1000)
第二行代表n门课各自的截止时间,
第三行代表n门课各自有几分。
输出:
最小的总的降低的分数
ll t,n,m,p,q;
bool vis[maxn];
struct node{
ll da,score;
}a[maxn];
string s;
bool cmp(node x,node y){
if(x.score!=y.score) return x.score>y.score;
return x.da<y.da;
}
int main(){
cin>>t;
while(t--){
ll ans=0;
memset(vis,0,sizeof vis);
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i].da;
for(int i=1;i<=n;i++) cin>>a[i].score;
sort(a+1,a+n+1,cmp);
for(int i=1;i<=n;i++){
int j;
for(j=a[i].da;j>0;j--){
if(!vis[j]){
vis[j]=1;
break;
}
}
if(j==0) ans+=a[i].score;
}
cout<<ans<<endl;
}
return 0;
}
要保证失分最小,就让分数多的作业尽可能都能做完,当然,如果这个作业有好几天的截止日期,只要将这个作业安排在截止日期前一天完成。如果这个位置已经有作业安排在了这一天,那就继续往前找,知道找到第一天。这样就可以保证最优。
先按照cmp排序,
按照分数大小排,分数大的在前,如果分数相同,就截止日期早的在前,
一个作业做1天,那n个作业就一共要最多n天
从1到n天循环,
每次再看改项目截止日期之前是不是还有位置,如果有就插入。