# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1208689 | horiaboeriu | Table Tennis (info1cup20_tabletennis) | C++20 | 47 ms | 2888 KiB |
#include <bits/stdc++.h>
using namespace std;
#define MAXN 150000
#define MAXK 400
int v[MAXN + MAXK], f[MAXN + MAXK];
int nr;
char verif(int st, int dr, int k, int n2) {
int i, j, s;
f[st] = f[dr] = nr;
s = v[st] + v[dr];
i = st + 1;
j = dr - 1;
while (k >= 0 && i < j) {
if (v[i] + v[j] < s) {
i++;
k--;
} else if (v[i] + v[j] > s) {
j--;
k--;
} else {
if (n2 > 0) {
f[i] = f[j] = nr;//le pastrez in solutie
n2 -= 2;
}
i++;
j--;
}
}
return (k >= 0);//daca returneaza 1 am gasit o solutie
}
int main()
{
int n, k, i, j, rez, n2;
scanf("%d%d", &n, &k);
n2 = n;
n += k;
for (i = 0; i < n; i++) {
scanf("%d", &v[i]);
}
//trebuie sa sterg k, deci capetele st si dr vor fi sigur din primele k + 1 si ultimele k + 1
//O(k^2 * n)
i = rez = 0;
while (i <= k && rez == 0) {
j = 0;
while (j <= k - i && rez == 0) {
nr++;
rez = verif(i, n - 1 - j, k - i - j, n2 - 2);//pozitiile st dr care sunt fixate si cate trebuei se elimin de la st + 1 la dr - 1
j++;
}
i++;
}
for (i = 0; i < n; i++) {
if (f[i] == nr) {
printf("%d ", v[i]);
}
}
fputc('\n', stdout);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |