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;
#define MASK(x) (1LL << (x))
#define BIT(x, i) (((x) >> (i)) & 1)
#define ALL(x) (x).begin(), (x).end()
#define REP(i, n) for (int i = 0, _n = n; i < _n; ++i)
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#define FORE(it, s) for (__typeof(s.begin()) it = (s).begin(); it != (s).end(); ++it)
#define TIME (1.0 * clock() / CLOCKS_PER_SEC)
#define file(TASK) \
if (fopen(TASK ".inp", "r")) { \
freopen(TASK ".inp", "r", stdin); \
freopen(TASK ".out", "w", stdout); \
}
template <class U, class V> bool maximize(U &A, const V &B) { return (A < B) ? (A = B, true) : false; }
template <class U, class V> bool minimize(U &A, const V &B) { return (A > B) ? (A = B, true) : false; }
const int MAXN = 2e5 + 5;
int N, K, a[MAXN];
void check (int sum) {
vector <int> ans;
for (int i = 1, j = N + K; i < j; i++) {
while(j > i && a[j] + a[i] > sum) --j;
if(j > i && a[i] + a[j] == sum) {
ans.push_back(a[i]);
ans.push_back(a[j]);
}
}
if((int) ans.size() == N) {
sort(ALL(ans));
for (auto x : ans) cout << x << " ";
exit(0);
}
}
void process(void) {
cin >> N >> K;
FOR(i, 1, N + K) cin >> a[i];
sort(a + 1, a + N + K + 1);
if(4 * K >= N) {
FOR(i, 1, N + K) FOR(j, i + 1, N + K) check(a[i] + a[j]);
}
map <int, int> mp;
FOR(i, 1, 2 * K) FOR(j, N - K + 1, N + K) mp[a[i] + a[j]]++;
for (auto [sum, cnt] : mp) if(cnt >= K) check(sum);
}
signed main() {
file("TASK");
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int test = 1;
// cin >> test;
while(test--) {
process();
cout << '\n';
}
cerr << "Time elapsed: " << TIME << " s.\n";
return (0 ^ 0);
}
Compilation message (stderr)
tabletennis.cpp: In function 'int main()':
tabletennis.cpp:17:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
17 | freopen(TASK ".inp", "r", stdin); \
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
tabletennis.cpp:61:5: note: in expansion of macro 'file'
61 | file("TASK");
| ^~~~
tabletennis.cpp:18:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
18 | freopen(TASK ".out", "w", stdout); \
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
tabletennis.cpp:61:5: note: in expansion of macro 'file'
61 | file("TASK");
| ^~~~
# | 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... |