http://acm.guet.edu.cn/problemset/problem/1118
排序:主:代价降序,次:截止时间降序。
从大到小取出元素,若当前的日期已经占用则向前一天查询(循环)。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAX_N = 1001;
int N, T;
struct W
{
int t, v;
bool operator<(const W x) const
{
if(this->v == x.v) return this->t > x.t;
return this->v > x.v;
}
}w[MAX_N];
int vis[MAX_N];
int main()
{
//freopen("in.txt", "r", stdin);
scanf("%d", &T);
while(T--)
{
int ans = 0;
scanf("%d", &N);
for(int i = 0; i < N; i++) scanf("%d", &w[i].t);
for(int i = 0; i < N; i++) scanf("%d", &w[i].v), ans+=w[i].v;
sort(w, w+N);
memset(vis, 0, sizeof(vis));
for(int i = 0; i < N; i++)
{
int t = w[i].t;
while (t > 0 && vis[t]) t--;
if(t==0) continue;
ans -= w[i].v;
vis[t] = 1;
}
printf("%d\n", ans);
}
return 0;
}