基础单调队列:
#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[];
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=;
t=;
while(!q.empty()) q.pop();
scanf("%d",&n);
for(i=;i<=n;i++) scanf("%d",&c[i].d);
for(i=;i<=n;i++) scanf("%d",&c[i].s);
sort(c+,c+n+,cmp);
for(i=;i<=n;i++){
q.push(c[i].s);
if(c[i].d>t) t++;
else {
ans+=q.top();q.pop();
}
}
printf("%d\n",ans);
}
return ;
}