标签:mil namespace const ace algo str -- names map
优先队列
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string.h>
#include<map>
#include<queue>
using namespace std;
#define ll long long
const int N=1e6+10;
struct node
{
int data,score;
friend bool operator <(node a,node b)
{
return a.score>b.score;
}
} p[N];
bool cmp(node a,node b)
{
if(a.data==b.data)
return a.score>b.score;
return a.data<b.data;
}
int b[N];
int dp[N];
int main()
{
int T,j,n,i,sum;
scanf("%d",&T);
while(T--)
{
node m;
sum=0;
priority_queue<node>Q;
memset(p,0x3f3f3f3f,sizeof(p));
scanf("%d",&n);
for(i=0; i<n; i++)
scanf("%d",&p[i].data);
for(i=0; i<n; i++)
scanf("%d",&p[i].score);
sort(p,p+n,cmp);
for(i=0,j=1;i<n;i++)
{
if(j<=p[i].data)
{
Q.push(p[i]);
j++;
}
else
{
m=Q.top();
if(m.score<p[i].score)
{
sum+=m.score;
Q.pop();
Q.push(p[i]);
}
else
{
sum+=p[i].score;
}
}
}
printf("%d\n",sum);
}
return 0;
}
标签:mil namespace const ace algo str -- names map
原文地址:https://www.cnblogs.com/zl1998/p/10809524.html