forked from laviii123/Btecky
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Job Scheduling
64 lines (57 loc) · 1.41 KB
/
Job Scheduling
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
bool cmp(pair<long long ,long long> a, pair<long long,long long> b){
if(a.second>b.second){
return true;
}
return false;
}
int main() {
long long t;
cin>>t;
while(t-->0){
long long n;
long long sum=0;
cin>>n;
vector<pair<long long,long long>> v;
vector<long long> a(n);
vector<long long> b(n);
vector<long long> visited(n+1,-1);
for(long long i=0; i<n; i++){
cin>>a[i];
}
for(long long i=0; i<n; i++){
cin>>b[i];
}
for(long long i=0; i<n; i++){
v.push_back(make_pair(a[i],b[i]));
}
sort(v.begin(),v.end(),cmp);
for(long long i=0; i<n; i++){
if(visited[v[i].first]==-1){
visited[v[i].first]=v[i].second;
}
else{
long long j=v[i].first-1;
while(j>0){
if(visited[j]==-1){
visited[j]=v[i].second;
break;
}
j--;
}
}
}
for(long long i=1; i<n+1; i++){
if(visited[i]!=-1){
sum+=visited[i];
}
}
cout<<sum<<endl;
}
return 0;
}