基础单调队列:
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<memory.h>
#include<queue>
using namespace std;
priority_queue<int,vector<int>,greater<int> >q;
struct in
{
int d,s;//deadline,score
}c[1010];
bool cmp(in a,in b){
return a.d<b.d;
}
int main()
{
int T,n,i,j,t,cnt,ans;
scanf("%d",&T);
while(T--){
cnt=ans=0;
t=0;
while(!q.empty()) q.pop();
scanf("%d",&n);
for(i=1;i<=n;i++) scanf("%d",&c[i].d);
for(i=1;i<=n;i++) scanf("%d",&c[i].s);
sort(c+1,c+n+1,cmp);
for(i=1;i<=n;i++){
q.push(c[i].s);
if(c[i].d>t) t++;
else {
ans+=q.top();q.pop();
}
}
printf("%d
",ans);
}
return 0;
}