题意:有t组测试数据,每组测试数据中有n门功课,第一排完成它们的时间限制,第二排是未在限制的时间内完成的要扣除的分数,然后是需要求扣的分数最少。
思路:先按照扣分从大到小排序,分数相同则按照截止日期从小到大排序。然后按顺序,从截止日期开始往前找没有占用掉的时间。如果找不到了,则改分数加到罚分里面。
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<string>
#include<cstring>
#include<cstdio>
const int maxn=10005;
const int INF=0x3f3f3f3f;
typedef long long LL;
using namespace std;
struct node
{
int t,s; //时间,扣的分数
}P[maxn];
int used[maxn]; //当前时间有没有用过
bool cmp(node a,node b) //分数按大到小排序,分数相同则按截至时间小到大排
{
return a.s==b.s?a.t<b.t:a.s>b.s;
}
int main()
{
// freopen("E:\\ACM\\test.txt","r",stdin);
int T,N;
cin>>T;
while(T--)
{
cin>>N;
memset(used,0,sizeof(used));
for(int i=0;i<N;i++) cin>>P[i].t;
for(int i=0;i<N;i++) cin>>P[i].s;
sort(P,P+N,cmp);
int ans=0,i,j;
for(i=0;i<N;i++)
{
for(j=P[i].t;j>0;j--) //从当前截至时间往前找没有用过的时间
{
if(!used[j])
{
used[j]=1;
break;
}
}
if(j==0) ans+=P[i].s; //找不到
}
cout<<ans<<endl;
}
return 0;
}