// Saarland University: <(OvO)> #include #define sz(a) ((int)(a).size()) #define divceil(a, b) ((a) + (b) - 1) / (b) using namespace std; #ifdef ONPC string to_string(const char* s) { return s; } template string to_string(const T& cont) { string ans = ""; for (bool fst = true; const auto& val: cont) { if (!fst) { ans += ", "; } ans += to_string(val); fst = false; } return ans + "}"; } void debug_print_collection() { cerr << endl; } template void debug_print_collection(First val, Args... args) { cerr << " " << to_string(val); debug_print_collection(args...); } #define debug(...) { cerr << "@@@ [" << #__VA_ARGS__ << "] ="; debug_print_collection(__VA_ARGS__);} #else #define debug(...) ; #define NDEBUG #endif mt19937 rnd(123); typedef long long ll; typedef long double ld; int solve() { int N; vector n(3); if (!(cin >> N >> n[0] >> n[1] >> n[2])) { return 1; } ld t0 = clock() * 1.0 / CLOCKS_PER_SEC; vector x(N); ll suma = 0; for (int i = 0; i < N; i++) { cin >> x[i]; suma += x[i]; } ll mx = (suma - 1) / 2; sort(x.begin(), x.end()); vector inds = {0, 1, 2}; sort(inds.begin(), inds.end(), [&](int i, int j) { return n[i] > n[j]; }); vector> q(3); int ii = 0; vector sum(3); for (int j : inds) { for (int i = ii; i < ii + n[j]; i++) { q[j].insert(x[i]); sum[j] += x[i]; } ii += n[j]; } int cntit = N * 15; while (true) { cntit--; if (cntit < 0) { break; } int j = 0; while (j < 3 && sum[j] <= mx) { j++; } if (j == 3) { break; } int k = (j + 1) % 3; if (rnd() % 2) { k = (k + 1) % 3; } ll t = *q[j].rbegin(); ll s = *q[k].begin(); sum[j] += s - t; sum[k] += t - s; q[j].erase(q[j].lower_bound(t)); q[j].insert(s); q[k].erase(q[k].lower_bound(s)); q[k].insert(t); } if (max({sum[0], sum[1], sum[2]}) > mx) { cout << "NO\n"; return 0; } cout << "YES\n"; for (int i = 0; i < 3; i++) { for (int j : q[i]) { cout << j << ' '; } cout << '\n'; } return 0; } int32_t main() { #ifdef ONPC assert(freopen("K.txt", "r", stdin)); #endif int TET = 1e9; cin >> TET; for (int i = 1; i <= TET; i ++) { if (solve()) { break; } #ifdef ONPC cout << "__________________" << endl; #endif } #ifdef ONPC cerr << endl << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl; #endif } /* g++ -std=c++20 -Wall -Wextra -Wshadow -D_GLIBCXX_DEBUG -DONPC -O2 -fsanitize=address -fsanitize=undefined -fno-sanitize-recover -o ex template.cpp && ./ex */