Submission #752220

#TimeUsernameProblemLanguageResultExecution timeMemory
752220AliHasanliTable Tennis (info1cup20_tabletennis)C++17
100 / 100
62 ms5776 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...