|

General

# Author Problem Lang Verdict Time Memory Sent Judged
208192875 Practice:
computerbigboom
1832B - 13 GNU C++20 (64) Accepted 389 ms 4052 KB 2023-06-02 19:45:55 2023-06-02 19:45:55
→ Source
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;

int main(){
lli t, n, k;
vector<lli> a;
lli temp;
lli ans1, ans2;
cin >> t;
lli ptr_2_min, ptr_max;
bool flag;
for (lli i = 0; i < t; ++i){
cin >> n >> k;
a.clear();
for (lli j = 0; j < n; ++j){
cin >> temp;
a.push_back(temp);
}
sort(a.begin(), a.end());
ptr_2_min = 2*k-1;
ptr_max = n-1;
flag = true;
while (flag && ptr_2_min > 0){
if (a[ptr_2_min] + a[ptr_2_min-1] >= a[ptr_max]){
ptr_2_min -= 2;
--ptr_max;
}
else {
flag = false;
}
}
ans1 = 0;
for (lli j = ptr_2_min+1; j <= ptr_max; ++j){
ans1 += a[j];
}
ptr_2_min = 0;
ptr_max = n-k;
flag = true;
while (flag && ptr_max < n){
if (a[ptr_2_min] + a[ptr_2_min+1] < a[ptr_max]){
ptr_2_min += 2;
++ptr_max;
}
else {
flag = false;
}
}
ans2 = 0;
for (lli j = ptr_2_min; j < ptr_max; ++j){
ans2 += a[j];
}
cout << max(ans1,ans2) << endl;
}
return 0;
}
?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
Jury's answer
?
Checker comment
?
Diagnostics
?
Click to see test details