#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
const int maxn = 2000;
const int maxc = 50;
const int inf = 1e16 + 42;
struct computer {
int cores, freq, val;
bool real;
bool operator < (const computer & other) const {
if(freq == other.freq) {
return real > other.real;
}
return freq > other.freq;
}
};
int n, m;
vector<computer> all;
vector<int> dp;
void solve() {
cin >> n;
for(int i = 1; i <= n; i++) {
computer cur;
cin >> cur.cores >> cur.freq >> cur.val;
cur.real = true;
all.pb(cur);
}
cin >> m;
for(int i = 1; i <= m; i++) {
computer cur;
cin >> cur.cores >> cur.freq >> cur.val;
cur.real = false;
all.pb(cur);
}
sort(all.begin(), all.end());
dp.assign(1 + maxn * maxc, -inf);
dp[0] = 0;
for(computer cur : all) {
if(cur.real) {
for(int i = maxn * maxc; i >= cur.cores; i--) {
dp[i] = max(dp[i], dp[i - cur.cores] - cur.val);
}
} else {
for(int i = 0; i <= maxn * maxc - cur.cores; i++) {
dp[i] = max(dp[i], dp[i + cur.cores] + cur.val);
}
}
}
int ans = 0;
for(int i = 0; i <= maxn * maxc; i++) {
ans = max(ans, dp[i]);
}
cout << ans << "\n";
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1108 KB |
Output is correct |
2 |
Correct |
1 ms |
1108 KB |
Output is correct |
3 |
Correct |
9 ms |
1108 KB |
Output is correct |
4 |
Correct |
17 ms |
1108 KB |
Output is correct |
5 |
Correct |
154 ms |
1236 KB |
Output is correct |
6 |
Correct |
149 ms |
1160 KB |
Output is correct |
7 |
Correct |
154 ms |
1236 KB |
Output is correct |
8 |
Correct |
160 ms |
1224 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1088 KB |
Output is correct |
2 |
Correct |
2 ms |
1108 KB |
Output is correct |
3 |
Correct |
9 ms |
1108 KB |
Output is correct |
4 |
Correct |
9 ms |
1108 KB |
Output is correct |
5 |
Correct |
75 ms |
1108 KB |
Output is correct |
6 |
Correct |
71 ms |
1104 KB |
Output is correct |
7 |
Correct |
181 ms |
1172 KB |
Output is correct |
8 |
Correct |
161 ms |
1236 KB |
Output is correct |
9 |
Correct |
167 ms |
1236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1088 KB |
Output is correct |
2 |
Correct |
3 ms |
1108 KB |
Output is correct |
3 |
Correct |
14 ms |
1084 KB |
Output is correct |
4 |
Correct |
14 ms |
1108 KB |
Output is correct |
5 |
Correct |
29 ms |
1108 KB |
Output is correct |
6 |
Correct |
27 ms |
1108 KB |
Output is correct |
7 |
Correct |
41 ms |
1108 KB |
Output is correct |
8 |
Correct |
43 ms |
1088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
980 KB |
Output is correct |
2 |
Correct |
2 ms |
1108 KB |
Output is correct |
3 |
Correct |
120 ms |
1236 KB |
Output is correct |
4 |
Correct |
137 ms |
1236 KB |
Output is correct |
5 |
Correct |
293 ms |
1364 KB |
Output is correct |
6 |
Correct |
310 ms |
1364 KB |
Output is correct |
7 |
Correct |
296 ms |
1364 KB |
Output is correct |
8 |
Correct |
300 ms |
1364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1108 KB |
Output is correct |
2 |
Correct |
12 ms |
1108 KB |
Output is correct |
3 |
Correct |
60 ms |
1104 KB |
Output is correct |
4 |
Correct |
145 ms |
1228 KB |
Output is correct |
5 |
Correct |
328 ms |
1364 KB |
Output is correct |
6 |
Correct |
327 ms |
1356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1108 KB |
Output is correct |
2 |
Correct |
1 ms |
1108 KB |
Output is correct |
3 |
Correct |
9 ms |
1108 KB |
Output is correct |
4 |
Correct |
17 ms |
1108 KB |
Output is correct |
5 |
Correct |
154 ms |
1236 KB |
Output is correct |
6 |
Correct |
149 ms |
1160 KB |
Output is correct |
7 |
Correct |
154 ms |
1236 KB |
Output is correct |
8 |
Correct |
160 ms |
1224 KB |
Output is correct |
9 |
Correct |
1 ms |
1088 KB |
Output is correct |
10 |
Correct |
2 ms |
1108 KB |
Output is correct |
11 |
Correct |
9 ms |
1108 KB |
Output is correct |
12 |
Correct |
9 ms |
1108 KB |
Output is correct |
13 |
Correct |
75 ms |
1108 KB |
Output is correct |
14 |
Correct |
71 ms |
1104 KB |
Output is correct |
15 |
Correct |
181 ms |
1172 KB |
Output is correct |
16 |
Correct |
161 ms |
1236 KB |
Output is correct |
17 |
Correct |
167 ms |
1236 KB |
Output is correct |
18 |
Correct |
3 ms |
1088 KB |
Output is correct |
19 |
Correct |
3 ms |
1108 KB |
Output is correct |
20 |
Correct |
14 ms |
1084 KB |
Output is correct |
21 |
Correct |
14 ms |
1108 KB |
Output is correct |
22 |
Correct |
29 ms |
1108 KB |
Output is correct |
23 |
Correct |
27 ms |
1108 KB |
Output is correct |
24 |
Correct |
41 ms |
1108 KB |
Output is correct |
25 |
Correct |
43 ms |
1088 KB |
Output is correct |
26 |
Correct |
2 ms |
980 KB |
Output is correct |
27 |
Correct |
2 ms |
1108 KB |
Output is correct |
28 |
Correct |
120 ms |
1236 KB |
Output is correct |
29 |
Correct |
137 ms |
1236 KB |
Output is correct |
30 |
Correct |
293 ms |
1364 KB |
Output is correct |
31 |
Correct |
310 ms |
1364 KB |
Output is correct |
32 |
Correct |
296 ms |
1364 KB |
Output is correct |
33 |
Correct |
300 ms |
1364 KB |
Output is correct |
34 |
Correct |
2 ms |
1108 KB |
Output is correct |
35 |
Correct |
12 ms |
1108 KB |
Output is correct |
36 |
Correct |
60 ms |
1104 KB |
Output is correct |
37 |
Correct |
145 ms |
1228 KB |
Output is correct |
38 |
Correct |
328 ms |
1364 KB |
Output is correct |
39 |
Correct |
327 ms |
1356 KB |
Output is correct |
40 |
Correct |
75 ms |
1096 KB |
Output is correct |
41 |
Correct |
163 ms |
1224 KB |
Output is correct |
42 |
Correct |
247 ms |
1364 KB |
Output is correct |
43 |
Correct |
320 ms |
1364 KB |
Output is correct |
44 |
Correct |
298 ms |
1364 KB |
Output is correct |
45 |
Correct |
311 ms |
1364 KB |
Output is correct |
46 |
Correct |
151 ms |
1168 KB |
Output is correct |
47 |
Correct |
236 ms |
1364 KB |
Output is correct |
48 |
Correct |
260 ms |
1364 KB |
Output is correct |