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;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define OPT ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(v) v.begin(), v.end()
#define mpr make_pair
#define eb emplace_back
#define pb push_back
#define ts to_string
#define fi first
#define se second
#define ins insert
#define int ll
#define inf 0x3F3F3F3F
#define infll 0x3F3F3F3F3F3F3F3FLL
#define bpc __builtin_popcount
int n, k;
int N;
vector<int> v;
bool solve(int l, int r, int u)
{
l++;
r--;
if (l > r) return true;
int pl = l - 1;
int pr = r + 1;
int cnt = 1;
while (l < r && u <= k)
{
if (v[pr] - v[r] < v[l] - v[pl])
{
r--;
u++;
}
else if (v[pr] - v[r] > v[l] - v[pl])
{
l++;
u++;
}
else
{
pl = l;
pr = r;
l++;
r--;
cnt++;
}
}
if (cnt >= n/2) return true;
return false;
}
void answer(int l, int r, int u)
{
vector<int> res;
res.pb(v[l]);
res.pb(v[r]);
l++;
r--;
int pl = l - 1;
int pr = r + 1;
int cnt = 1;
while (l < r && u <= k)
{
if (v[pr] - v[r] < v[l] - v[pl])
{
r--;
u++;
}
else if (v[pr] - v[r] > v[l] - v[pl])
{
l++;
u++;
}
else
{
res.pb(v[l]);
res.pb(v[r]);
pl = l;
pr = r;
l++;
r--;
cnt++;
}
}
sort(all(res));
for (int i = 0; i < n; i++)
{
cout << res[i] << " ";
}
cout << endl;
}
void _()
{
cin >> n >> k;
N = n + k;
v.assign(N + 1, 0);
for (int i = 1; i <= N; i++) cin >> v[i];
for (int i = 0; i <= k; i++)
{
for (int j = 0; j + i <= k; j++)
{
if (solve(i + 1, N - j, i + j))
{
answer(i + 1, N - j, i + j);
return;
}
}
}
}
int32_t main()
{
OPT;
_();
}
# | 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... |