#include #include using namespace std; using namespace __gnu_pbds; using ll = long long; using pii = pair; #define f first #define s second using ost = tree, rb_tree_tag, tree_order_statistics_node_update>; struct fenwick { int n; vector v; fenwick() {} fenwick(int _n) : n(_n) { v = vector(n + 2); } void add(int x, ll inc) { for (x++; x <= n; x += x&-x) v[x] += inc; } ll get(int x) { if (++x < 0) return 0; ll res = 0; for (; x; x -= x&-x) res += v[x]; return res; } ll get(int x, int y) { return get(y) - get(x - 1); } }; void solve() { int n, na, nb, nc, z; scanf("%d%d%d%d", &n, &na, &nb, &nc); vector x; bool swapab = false, swapbc = false, swapab2 = false; if (na > nb) { swap(na, nb); swapab = true; } if (nb > nc) { swap(nb, nc); swapbc = true; } if (na > nb) { swap(na, nb); swapab2 = true; } ll totalsum = 0; fenwick total(n); for (int i=1; i<=n; i++) { scanf("%d", &z); x.emplace_back(z, i); totalsum += z; } ll limit = (totalsum - 1) / 2; sort(x.begin(), x.end()); ost exist; for (int i=0; i targets = {na, nb, nc}; vector> res(3); for (int i=0; i<2; i++) { ll allowed = limit; for (int sz = targets[i]; sz; sz--) { int low = -1, high = exist.size() - sz, mid; while (low != high) { mid = (low + high + 1) / 2; int l = *exist.find_by_order(mid), r = *exist.find_by_order(mid + sz - 1); if (total.get(l, r) <= allowed) low = mid; else high = mid - 1; } if (low == -1) { printf("NO\n"); return; } int pos = *exist.find_by_order(low); total.add(pos, -x[pos].f); exist.erase(pos); res[i].push_back(x[pos].f); allowed -= x[pos].f; totalsum -= x[pos].f; } } if (totalsum > limit) { printf("NO\n"); return; } for (int i : exist) res[2].push_back(x[i].f); if (swapab2) swap(res[0], res[1]); if (swapbc) swap(res[1], res[2]); if (swapab) swap(res[0], res[1]); printf("YES\n"); for (auto& v : res) { for (int j=0; j