
D - Cake 123
The Patisserie AtCoder sells cakes with number-shaped candles. There are X, Y and Z kinds of cakes with 1-shaped, 2-shaped and 3-shaped candles, respectively. Each cake has an integer value called deliciousness, as follows:


Input is given from Standard Input in the following format:
X Y Z K
A1 A2 A3 ... AX
B1 B2 B3 ... BY
C1 C2 C3 ... CZ
Print K lines. The i-th line should contain the i-th value stated in the problem statement.
2 2 2 8
4 6
1 5
3 8
19
17
15
14
13
12
10
8
3 3 3 5
1 10 100
2 20 200
1 10 100
400
310
310
301
301
10 10 10 20
7467038376 5724769290 292794712 2843504496 3381970101 8402252870 249131806 6310293640 6690322794 6082257488
1873977926 2576529623 1144842195 1379118507 6003234687 4925540914 3902539811 3326692703 484657758 2877436338
4975681328 8974383988 2882263257 7690203955 514305523 6679823484 4263279310 585966808 3752282379 620585736
23379871545
22444657051
22302177772
22095691512
21667941469
21366963278
21287912315
21279176669
21160477018
21085311041
21059876163
21017997739
20703329561
20702387965
20590247696
20383761436
20343962175
20254073196
20210218542
20150096547
Note that the input or output may not fit into a 32-bit integer type.
void coder_solution() {
// 提升cin、cout效率
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long x, y, z, k;
cin >> x >> y >> z >> k;
vector<long long> a(x);
vector<long long> b(y);
vector<long long> c(z);
for (int i = 0; i < x; i++) {
cin >> a[i];
}
sort(a.begin(), a.end(), greater<long long>());
for (int i = 0; i < y; i++) {
cin >> b[i];
}
sort(b.begin(), b.end(), greater<long long>());
for (int i = 0; i < z; i++) {
cin >> c[i];
}
sort(c.begin(), c.end(), greater<long long>());
vector<long long> vll;
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
for (int s = 0; s < z; s++) {
if ((i + 1) * (j + 1) * (s + 1) <= k) {
vll.push_back(a[i] + b[j] + c[s]);
} else {
break;
}
}
}
}
sort(vll.begin(), vll.end(), greater<long long>());
for (int i = 0; i < k; i++) {
cout << vll[i] << endl;
}
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007ll;
int x, y, z, k;
ll a[1252], b[1252], c[1252];
int main() {
scanf("%d%d%d%d", &x, &y, &z, &k);
for (int i = 0; i < x; i++) {
scanf("%lld", a + i);
}
for (int i = 0; i < y; i++) {
scanf("%lld", b + i);
}
for (int i = 0; i < z; i++) {
scanf("%lld", c + i);
}
multiset<ll> Q;
Q.insert(0);
int aaa[] = {x, y, z};
ll *bbb[] = {a, b, c};
for (int t = 0; t < 3; t++) {
int n = aaa[t];
ll *ar = bbb[t];
multiset<ll> R;
while (Q.size()) {
ll v = *Q.begin();
Q.erase(Q.begin());
for (int i = 0; i < n; i++) {
R.insert(v + ar[i]);
}
while (R.size() > k) {
R.erase(R.begin());
}
}
Q = R;
}
auto it = Q.rbegin();
while (it != Q.rend()) {
printf("%lld\n", *it);
it++;
}
return 0;
}
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
using lint = long long;
const lint mod = 256;
template<class itr>
void cins(itr first, itr last) {
for (auto i = first; i != last; i++) {
cin >> (*i);
}
}
using p = pair<lint, int>;
int main() {
int X, Y, Z, K;
cin >> X >> Y >> Z >> K;
lint A[X], B[Y], C[Z];
cins(A, A + X);
cins(B, B + Y);
cins(C, C + Z);
sort(C, C + Z, greater<lint>());
priority_queue<p> pairs;
for (int i = 0; i < X; i++) {
for (int j = 0; j < Y; j++) {
pairs.push({A[i] + B[j] + C[0], 0});
}
}
for (int i = 0; i < K; i++) {
auto top = pairs.top();
pairs.pop();
cout << top.first << endl;
if (top.second == Z - 1) {
continue;
}
pairs.push({top.first - C[top.second] + C[top.second + 1], top.second + 1});
}
}
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define REP(i, m, n) for(int i=(int)(m) ; i < (int) (n) ; ++i)
#define rep(i, n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;
int main() {
ll x, y, z, k;
cin >> x >> y >> z >> k;
ll a[x], b[y], c[z];
rep(i, x) cin >> a[i];
rep(i, y) cin >> b[i];
rep(i, z) cin >> c[i];
vector<ll> cur;
rep(i, x)
rep(j, y) {
cur.push_back(a[i] + b[j]);
}
sort(cur.rbegin(), cur.rend());
if (cur.size() > k) {
cur.resize(k);
}
vector<ll> res;
rep(i, cur.size())
rep(j, z) {
res.push_back(cur[i] + c[j]);
}
sort(res.rbegin(), res.rend());
rep(i, k) {
cout << res[i] << endl;
}
return 0;
}