이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define fr first
#define sc second
#define all(x) (x).begin(), (x).end()
#define pw(x) (1ll << x)
#define pb push_back
#define endl '\n'
#define sz(x) (int)((x).size())
using namespace std;
template <typename T> inline bool umin (T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
template <typename T> inline bool umax (T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
typedef long long ll;
typedef pair <int, int> pii;
inline void solve () {
int n, k; cin >> n >> k;
vector <int> a (n + k);
for (auto &i : a) cin >> i;
sort(all(a));
set <int> used;
for (int i = 0; i < k + 1; ++i) {
for (int j = n + k - 1; j >= n - 2; --j) {
if (used.find(a[i] + a[j]) != used.end()) continue;
int s = a[i] + a[j];
used.insert(s);
int l = i + 1, r = j - 1;
vector <int> ans; ans.reserve(n);
ans.pb(a[i]); ans.pb(a[j]);
while (l <= r && sz(ans) < n) {
if (r - l + 1 + sz(ans) < n) break;
if (a[l] + a[r] == s) {
ans.pb(a[l]); ans.pb(a[r]);
++l, --r;
}
else if (a[l] + a[r] < s) ++l;
else --r;
}
if (sz(ans) == n) {
sort(all(ans));
for (auto x : ans) cout << x << " ";
return;
}
}
}
assert(0);
}
signed main () {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif // LOCAL
int t = 1; //cin >> t;
while (t--) solve();
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... |