Submission
Status:
P--PT-P-P-
Subtask/Task Score:
40/100
Score: 40
User: chillxvtkz
Problemset: ประลอง
Language: cpp
Time: 1.080 second
Submitted On: 2026-10-14 11:32:55
#include <bits/stdc++.h>
#define ll long long
#define ct cout << ' '
#define el cout << '\n'
using namespace std;
const int mx = 1e9;
const int mn = -1e9;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
if (!(cin >> n)) return 0;
vector<int> a(n), b(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
b[i] = i;
}
int c = n / 2;
ll d = 1e18;
vector<int> e, f;
int g = 5000000;
while (g--) {
random_shuffle(b.begin(), b.end());
ll u = 0, v = 0;
vector<int> x, y;
for (int i = 0; i < c; i++) {
u += a[b[i]];
x.push_back(b[i]);
}
for (int i = c; i < n; i++) {
v += a[b[i]];
y.push_back(b[i]);
}
if (abs(u - v) < d) {
d = abs(u - v);
e = x;
f = y;
}
if (d == 0) break;
}
sort(e.begin(), e.end());
sort(f.begin(), f.end());
for (int i : e) { cout << a[i]; ct; }el;
for (int i : f) { cout << a[i]; ct; }el;
return 0;
}