# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
689602 | LucaLucaM | Table Tennis (info1cup20_tabletennis) | C++17 | 156 ms | 4688 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
/**
trebuie sa alegem n din n + k numere astfel incat
a[1] + a[n] = a[2] + a[n-1] = ... = a[n/2] + a[n/2+1]
a[1] + a[n] = a[2] + a[n-1]
a[n] - a[n-1] = a[2] - a[1]
a[n-1] - a[n-2] = a[3] - a[2]
...
a[n/2+1] - a[n/2] = a[n] - a[n-1]
n*k + nlogn?
**/
int a[150401];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, k;
cin >> n >> k;
int m = n + k;
for (int i=1; i<=m; i++)
cin >> a[i];
for (int i=1; i<=k+1; i++) /// O(k)
{
/// incercam sa fie a[i] cel mai mic element , a[j] cel mai mare
for (int j=m; m-j+i-1 <= k; j--) /// O(k*k)
{
int sum = a[i] + a[j];
int l=i, r=j;
int cnt = 0;
while (l < r)
{
while (l < r && a[l] + a[r] > sum)
r--;
while (l < r && a[l] + a[r] < sum)
l++;
if (a[l] + a[r] != sum)
{
cnt = -1;
break;
}
cnt++;
l++;
}
if (cnt >= n/2)
{
cnt = n / 2;
vector<int>ans;
int l=i, r=j;
while (l < r && cnt--)
{
while (l < r && a[l] + a[r] > sum)
r--;
while (l < r && a[l] + a[r] < sum)
l++;
ans.push_back(a[l]);
ans.push_back(a[r]);
l++, r--;
}
for (int i=0; i<n; i+=2)
cout << ans[i] << ' ';
reverse(ans.begin(), ans.end());
for (int i=int(ans.size()) & 1; i<ans.size(); i+=2)
cout << ans[i] << ' ';
return 0;
}
}
}
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... |