-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path694C.cpp
More file actions
45 lines (43 loc) · 947 Bytes
/
694C.cpp
File metadata and controls
45 lines (43 loc) · 947 Bytes
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
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
scanf("%d", &t);
while (t--)
{
int k, m;
scanf("%d %d", &k, &m);
vector<int>arr;
int c;
for (int i = 0; i < k; i++)
{
scanf("%d", &c);
arr.push_back(c-1);
// arr[k].second = i;
}
// int m;
// scanf("%d", &m);
int gift[m];
for (int i = 0; i < m; i++)
{
scanf("%d", &gift[i]);
}
// printf("shdfj\n");
sort(arr.begin(),arr.end());
int l = 0;
long long int sum = 0;
for (int i = k-1; i >= 0; i--)
{
if(l <= arr[i] && gift[l] <= gift[arr[i]]){
sum += gift[l];
l++;
}
else
{
sum += gift[arr[i]];
}
}
printf("%lld\n",sum);
}
}