Submission #73539544
Source Code Expand
#include <iostream>
#include <algorithm>
#include <queue>
#define int long long
using namespace std;
int T;
int n, kk, l;
int a[200005];
priority_queue<int> q;
void solve()
{
cin >> n >> kk >> l;
for (int i = 1; i <= n; i++)
cin >> a[i];
sort(a + 1, a + n + 1);
int bg = a[1], ed = l - a[n], ans = 0, temp = 0;
for (int i = 2; i <= n; i++)
q.push((a[i] - a[i - 1]) / 2);
// cout << kk << '\n';
ans = max(bg, ed) + (kk - 1) * (bg + ed);
for (int i = 1; i <= kk; i++)
{
if (q.empty())
break;
temp += q.top();
bg += q.top(), ed += q.top(), q.pop();
// cout << bg << '|' << ed << '|' << temp << '\n';
ans = max(temp + (kk - i <= 0 ? 0 : max(bg, ed)) + (kk - i - 1 <= 0 ? 0 : (kk - i - 1) * (bg + ed)), ans);
}
while (!q.empty())
q.pop();
for (int i = 1; i <= n; i++)
a[i] = 0;
cout << ans << '\n';
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> T;
while (T--)
solve();
}
Submission Info
| Submission Time | |
|---|---|
| Task | A - Zombie |
| User | Hygrox |
| Language | C++23 (GCC 15.2.0) |
| Score | 500 |
| Code Size | 1100 Byte |
| Status | AC |
| Exec Time | 38 ms |
| Memory | 7216 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 500 / 500 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00_sample_01.txt |
| All | 00_sample_01.txt, hand-12.txt, hand-13.txt, hand-14.txt, large-15.txt, large-16.txt, large-17.txt, random-01.txt, random-02.txt, random-03.txt, random-04.txt, random-05.txt, random-06.txt, random-07.txt, random-08.txt, random-09.txt, random-10.txt, random-11.txt, small-18.txt, small-19.txt, small-20.txt, small-21.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00_sample_01.txt | AC | 1 ms | 3552 KiB |
| hand-12.txt | AC | 1 ms | 3472 KiB |
| hand-13.txt | AC | 16 ms | 3968 KiB |
| hand-14.txt | AC | 15 ms | 3964 KiB |
| large-15.txt | AC | 20 ms | 7152 KiB |
| large-16.txt | AC | 38 ms | 7100 KiB |
| large-17.txt | AC | 31 ms | 3960 KiB |
| random-01.txt | AC | 34 ms | 5228 KiB |
| random-02.txt | AC | 17 ms | 3636 KiB |
| random-03.txt | AC | 25 ms | 3660 KiB |
| random-04.txt | AC | 29 ms | 4052 KiB |
| random-05.txt | AC | 32 ms | 4276 KiB |
| random-06.txt | AC | 34 ms | 5148 KiB |
| random-07.txt | AC | 38 ms | 7216 KiB |
| random-08.txt | AC | 37 ms | 7068 KiB |
| random-09.txt | AC | 36 ms | 7092 KiB |
| random-10.txt | AC | 37 ms | 7100 KiB |
| random-11.txt | AC | 38 ms | 7100 KiB |
| small-18.txt | AC | 36 ms | 6968 KiB |
| small-19.txt | AC | 29 ms | 4064 KiB |
| small-20.txt | AC | 19 ms | 6960 KiB |
| small-21.txt | AC | 15 ms | 3964 KiB |