[ABC123D] Cake 123
题意:给(n,m,k)三个数代表三种蛋糕价格种类,然后分别要三种都买一个蛋糕,然后给(d)求前(d)贵的蛋糕价格。
题解:没大懂,就是暴力循环(i,j,k)当(i * j * k > d)时跳出,然后排序输出前(d)个
代码:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
ll a[ 3030], b[3030], c[3030];
ll ans[101010101];
bool cmp(ll a, ll b) {
return a > b;
}
void solve() {
ll ca, cb, cc, n;
cin >> ca >> cb >> cc >> n;
for (ll i = 1; i <= ca; i++) {
cin >> a[i];
}
for (ll i = 1; i <= cb; i++) {
cin >> b[i];
}
for (ll i = 1; i <= cc; i++) {
cin >> c[i];
}
sort(a + 1, a + 1 + ca, cmp);
sort(b + 1, b + 1 + cb, cmp);
sort(c + 1, c + 1 + cc, cmp);
ll ans_cnt = 0;
for (ll i = 1; i <= ca; i++) {
for (ll j = 1; j <= cb; j++) {
for (ll k = 1; k <= cc; k++) {
if (i * j * k > n)break;
ans[++ans_cnt] = a[i] + b[j] + c[k];
}
}
}
//cout << ans_cnt << endl;
sort(ans + 1,ans + 1 + ans_cnt);
for (ll i = ans_cnt; i >= 1 && n > 0; i--, n--) {
cout << ans[i] << endl;
}
}
signed main() {
ll t = 1;
//cin >> t;
while (t--) {
solve();
}
}