#include <bits/stdc++.h>
using i64 = long long;
constexpr int X = 50;
constexpr i64 inf = 1ll << 50;
void chmax(i64 &a, i64 b) {
a = std::max(a, b);
}
struct CPU {
int cores;
i64 rate;
i64 price;
bool operator<(const CPU &other) {
return rate < other.rate;
}
};
int main() {
int N;
std::cin >> N;
std::vector<CPU> stores(N);
for (auto &[c, r, p] : stores) {
std::cin >> c >> r >> p;
}
int M;
std::cin >> M;
std::vector<CPU> customers(M);
for (auto &[c, r, p] : customers) {
std::cin >> c >> r >> p;
}
std::sort(stores.begin(), stores.end());
std::sort(customers.begin(), customers.end());
std::vector<std::pair<CPU, bool>> data;
int id = 0;
for (int i = 0; i < N; ++i) {
while (id != M and customers[id].rate <= stores[i].rate) {
data.push_back({customers[id++], false});
}
data.push_back({stores[i], true});
}
while (id != M) {
data.push_back({customers[id++], false});
}
const int U = N + M;
std::vector<i64> dp(M * X + 1, -inf);
dp[0] = 0;
for (int i = 0; i < U; ++i) {
auto ndp = dp;
const auto &[cpu, type] = data[i];
if (type) {
// store
for (int j = M * X; j >= 0; --j) {
chmax(ndp[std::max(0, j - cpu.cores)], dp[j] - cpu.price);
}
} else {
for (int j = 0; j <= M * X - cpu.cores; ++j) {
chmax(ndp[j + cpu.cores], dp[j] + cpu.price);
}
}
dp = std::move(ndp);
}
std::cout << dp[0] << std::endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
304 KB |
Output is correct |
4 |
Correct |
3 ms |
468 KB |
Output is correct |
5 |
Correct |
205 ms |
2004 KB |
Output is correct |
6 |
Correct |
200 ms |
2004 KB |
Output is correct |
7 |
Correct |
232 ms |
2060 KB |
Output is correct |
8 |
Correct |
236 ms |
2060 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
296 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
3 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
6 ms |
520 KB |
Output is correct |
8 |
Correct |
5 ms |
468 KB |
Output is correct |
9 |
Correct |
4 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
300 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
4 ms |
340 KB |
Output is correct |
6 |
Correct |
5 ms |
340 KB |
Output is correct |
7 |
Correct |
12 ms |
436 KB |
Output is correct |
8 |
Correct |
12 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
296 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
188 ms |
1876 KB |
Output is correct |
5 |
Correct |
448 ms |
1972 KB |
Output is correct |
6 |
Correct |
582 ms |
2180 KB |
Output is correct |
7 |
Correct |
558 ms |
2260 KB |
Output is correct |
8 |
Correct |
514 ms |
2176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
400 KB |
Output is correct |
3 |
Correct |
16 ms |
572 KB |
Output is correct |
4 |
Correct |
163 ms |
1532 KB |
Output is correct |
5 |
Correct |
535 ms |
2264 KB |
Output is correct |
6 |
Correct |
539 ms |
2132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
304 KB |
Output is correct |
4 |
Correct |
3 ms |
468 KB |
Output is correct |
5 |
Correct |
205 ms |
2004 KB |
Output is correct |
6 |
Correct |
200 ms |
2004 KB |
Output is correct |
7 |
Correct |
232 ms |
2060 KB |
Output is correct |
8 |
Correct |
236 ms |
2060 KB |
Output is correct |
9 |
Correct |
1 ms |
296 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
3 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
6 ms |
520 KB |
Output is correct |
16 |
Correct |
5 ms |
468 KB |
Output is correct |
17 |
Correct |
4 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
300 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
4 ms |
340 KB |
Output is correct |
23 |
Correct |
5 ms |
340 KB |
Output is correct |
24 |
Correct |
12 ms |
436 KB |
Output is correct |
25 |
Correct |
12 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
296 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
29 |
Correct |
188 ms |
1876 KB |
Output is correct |
30 |
Correct |
448 ms |
1972 KB |
Output is correct |
31 |
Correct |
582 ms |
2180 KB |
Output is correct |
32 |
Correct |
558 ms |
2260 KB |
Output is correct |
33 |
Correct |
514 ms |
2176 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
2 ms |
400 KB |
Output is correct |
36 |
Correct |
16 ms |
572 KB |
Output is correct |
37 |
Correct |
163 ms |
1532 KB |
Output is correct |
38 |
Correct |
535 ms |
2264 KB |
Output is correct |
39 |
Correct |
539 ms |
2132 KB |
Output is correct |
40 |
Correct |
36 ms |
776 KB |
Output is correct |
41 |
Correct |
153 ms |
1416 KB |
Output is correct |
42 |
Correct |
308 ms |
1748 KB |
Output is correct |
43 |
Correct |
546 ms |
2260 KB |
Output is correct |
44 |
Correct |
528 ms |
2200 KB |
Output is correct |
45 |
Correct |
570 ms |
2260 KB |
Output is correct |
46 |
Correct |
140 ms |
1264 KB |
Output is correct |
47 |
Correct |
301 ms |
1748 KB |
Output is correct |
48 |
Correct |
284 ms |
1720 KB |
Output is correct |