#include <bits/stdc++.h>
using namespace std;
#define int long long
int n, m, inf = 1e15;
priority_queue<pair<pair<int, int>, pair<int, int>>> pq;
int dp[200005];
int c, f, v, a, ran = 0;
signed main() {
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
for(int i = 1; i <= 100000; i++) {
dp[i] = inf;
}
cin >> n;
for(int i = 0; i < n; i++) {
cin >> c >> f >> v;
pq.push({{f, c}, {v, 1}});
}
cin >> m;
for(int i = 0; i < m; i++) {
cin >> c >> f >> v;
pq.push({{f, c}, {v, 2}});
}
while(!pq.empty()) {
c = pq.top().first.second;
v = pq.top().second.first;
a = pq.top().second.second;
pq.pop();
if(a == 1) {
for(int i = 100000; i >= 0; i--) {
dp[i + c] = min(dp[i + c], dp[i] + v);
}
ran += c;
} else {
for(int i = c; i <= 100000; i++) {
dp[i - c] = min(dp[i - c], dp[i] - v);
}
}
}
int mini = 0;
for(int i = 0; i <= 100000; i++) {
mini = min(dp[i], mini);
}
mini *= -1;
cout << mini << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1116 KB |
Output is correct |
2 |
Correct |
1 ms |
1116 KB |
Output is correct |
3 |
Correct |
7 ms |
1116 KB |
Output is correct |
4 |
Correct |
13 ms |
1264 KB |
Output is correct |
5 |
Correct |
118 ms |
1380 KB |
Output is correct |
6 |
Correct |
116 ms |
1372 KB |
Output is correct |
7 |
Correct |
123 ms |
1372 KB |
Output is correct |
8 |
Correct |
117 ms |
1388 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1112 KB |
Output is correct |
2 |
Correct |
1 ms |
1116 KB |
Output is correct |
3 |
Correct |
8 ms |
1256 KB |
Output is correct |
4 |
Correct |
7 ms |
1116 KB |
Output is correct |
5 |
Correct |
57 ms |
1116 KB |
Output is correct |
6 |
Correct |
53 ms |
1116 KB |
Output is correct |
7 |
Correct |
142 ms |
1372 KB |
Output is correct |
8 |
Correct |
121 ms |
1392 KB |
Output is correct |
9 |
Incorrect |
116 ms |
1372 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1112 KB |
Output is correct |
2 |
Correct |
2 ms |
1224 KB |
Output is correct |
3 |
Correct |
11 ms |
1116 KB |
Output is correct |
4 |
Correct |
11 ms |
1116 KB |
Output is correct |
5 |
Correct |
22 ms |
1260 KB |
Output is correct |
6 |
Correct |
22 ms |
1116 KB |
Output is correct |
7 |
Correct |
30 ms |
1264 KB |
Output is correct |
8 |
Correct |
30 ms |
1116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
1116 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1112 KB |
Output is correct |
2 |
Correct |
10 ms |
1116 KB |
Output is correct |
3 |
Correct |
58 ms |
1288 KB |
Output is correct |
4 |
Correct |
116 ms |
1368 KB |
Output is correct |
5 |
Correct |
262 ms |
1372 KB |
Output is correct |
6 |
Correct |
242 ms |
1372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1116 KB |
Output is correct |
2 |
Correct |
1 ms |
1116 KB |
Output is correct |
3 |
Correct |
7 ms |
1116 KB |
Output is correct |
4 |
Correct |
13 ms |
1264 KB |
Output is correct |
5 |
Correct |
118 ms |
1380 KB |
Output is correct |
6 |
Correct |
116 ms |
1372 KB |
Output is correct |
7 |
Correct |
123 ms |
1372 KB |
Output is correct |
8 |
Correct |
117 ms |
1388 KB |
Output is correct |
9 |
Correct |
1 ms |
1112 KB |
Output is correct |
10 |
Correct |
1 ms |
1116 KB |
Output is correct |
11 |
Correct |
8 ms |
1256 KB |
Output is correct |
12 |
Correct |
7 ms |
1116 KB |
Output is correct |
13 |
Correct |
57 ms |
1116 KB |
Output is correct |
14 |
Correct |
53 ms |
1116 KB |
Output is correct |
15 |
Correct |
142 ms |
1372 KB |
Output is correct |
16 |
Correct |
121 ms |
1392 KB |
Output is correct |
17 |
Incorrect |
116 ms |
1372 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |