#include <bits/stdc++.h>
using namespace std;
struct Transaction {
int cores;
int rate;
int price;
};
int main() {
vector<Transaction> poss_transactions;
int max_computers = 0;
int comp_num;
cin >> comp_num;
for (int c = 0; c < comp_num; c++) {
Transaction trans;
cin >> trans.cores >> trans.rate >> trans.price;
trans.price = -trans.price;
poss_transactions.push_back(trans);
max_computers += trans.cores;
}
int order_num;
cin >> order_num;
for (int o = 0; o < order_num; o++) {
Transaction trans;
cin >> trans.cores >> trans.rate >> trans.price;
trans.cores = -trans.cores;
poss_transactions.push_back(trans);
}
sort(poss_transactions.begin(), poss_transactions.end(),
[](const Transaction &a, const Transaction &b) -> bool {
return a.rate != b.rate ? a.rate > b.rate : a.price < b.price;
});
vector<long long> max_profits(max_computers + 1, INT64_MIN);
max_profits[0] = 0;
for (const Transaction &t : poss_transactions) {
vector<long long> new_max(max_profits);
for (int c = 0; c <= max_computers; c++) {
int prev_comp = c - t.cores;
if (0 <= prev_comp && prev_comp <= max_computers &&
max_profits[prev_comp] != INT64_MIN) {
new_max[c] =
max(new_max[c], max_profits[prev_comp] + t.price);
}
}
max_profits = new_max;
}
cout << *max_element(max_profits.begin(), max_profits.end()) << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
432 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
4 ms |
528 KB |
Output is correct |
8 |
Correct |
3 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
432 KB |
Output is correct |
5 |
Correct |
31 ms |
672 KB |
Output is correct |
6 |
Correct |
2 ms |
348 KB |
Output is correct |
7 |
Correct |
173 ms |
1328 KB |
Output is correct |
8 |
Correct |
33 ms |
604 KB |
Output is correct |
9 |
Correct |
288 ms |
1712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
10 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
392 KB |
Output is correct |
5 |
Correct |
318 ms |
1368 KB |
Output is correct |
6 |
Correct |
599 ms |
1972 KB |
Output is correct |
7 |
Correct |
606 ms |
1940 KB |
Output is correct |
8 |
Correct |
578 ms |
1924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
33 ms |
856 KB |
Output is correct |
4 |
Correct |
7 ms |
344 KB |
Output is correct |
5 |
Correct |
552 ms |
1956 KB |
Output is correct |
6 |
Correct |
584 ms |
1944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
432 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
4 ms |
528 KB |
Output is correct |
8 |
Correct |
3 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
432 KB |
Output is correct |
13 |
Correct |
31 ms |
672 KB |
Output is correct |
14 |
Correct |
2 ms |
348 KB |
Output is correct |
15 |
Correct |
173 ms |
1328 KB |
Output is correct |
16 |
Correct |
33 ms |
604 KB |
Output is correct |
17 |
Correct |
288 ms |
1712 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
10 ms |
348 KB |
Output is correct |
29 |
Correct |
2 ms |
392 KB |
Output is correct |
30 |
Correct |
318 ms |
1368 KB |
Output is correct |
31 |
Correct |
599 ms |
1972 KB |
Output is correct |
32 |
Correct |
606 ms |
1940 KB |
Output is correct |
33 |
Correct |
578 ms |
1924 KB |
Output is correct |
34 |
Correct |
1 ms |
344 KB |
Output is correct |
35 |
Correct |
1 ms |
344 KB |
Output is correct |
36 |
Correct |
33 ms |
856 KB |
Output is correct |
37 |
Correct |
7 ms |
344 KB |
Output is correct |
38 |
Correct |
552 ms |
1956 KB |
Output is correct |
39 |
Correct |
584 ms |
1944 KB |
Output is correct |
40 |
Correct |
33 ms |
676 KB |
Output is correct |
41 |
Correct |
98 ms |
856 KB |
Output is correct |
42 |
Correct |
8 ms |
344 KB |
Output is correct |
43 |
Correct |
763 ms |
2140 KB |
Output is correct |
44 |
Correct |
709 ms |
2364 KB |
Output is correct |
45 |
Correct |
695 ms |
2140 KB |
Output is correct |
46 |
Correct |
4 ms |
344 KB |
Output is correct |
47 |
Correct |
8 ms |
568 KB |
Output is correct |
48 |
Correct |
7 ms |
348 KB |
Output is correct |