이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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];
sort(a+1, a+m+1);
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--;
}
sort(ans.begin(), ans.end());
for (int x : ans)
cout << x << ' ';
return 0;
}
}
}
return 0;
}
# | 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... |