-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathC - RationalLee.cpp
More file actions
50 lines (41 loc) · 828 Bytes
/
C - RationalLee.cpp
File metadata and controls
50 lines (41 loc) · 828 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
46
47
48
49
50
#define ll long long
#include<bits/stdc++.h>
using namespace std;
int main()
{
ll T;
cin>>T;
while(T--)
{
ll n, k, i, sum=0, x, y, ma, mi;
cin>>n;
cin>>k;
x = n-1; y = n-k-1;
ma = 0;
ll arr[n], a2[k];
for(i=0; i<n; i++)
cin >> arr[i];
for(i=0; i<k; i++)
cin >> a2[i];
sort(arr, arr+n);
sort(a2, a2+k);
for(i=0; i<k; i++)
{
if(a2[i] == 1)
{
ma = mi = arr[x];
x--;
}
else
{
ma = arr[x];
mi = arr[y-a2[i]+2];
x--;
y=y-a2[i]+1;
}
sum += ma + mi;
}
cout << sum << endl;
}
return 0;
}