#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct str{
ll c, f, v, type;
} niz[4005];
bool cmp(str a, str b){
if(a.f < b.f) return 0;
if(a.f > b.f) return 1;
return a.type > b.type;
}
ll dp[100005];
ll dpp[100005];
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
cout.precision(10);
cout << fixed;
int n;
cin >> n;
for(int i=1; i<=n; i++){
cin >> niz[i].c >> niz[i].f >> niz[i].v;
niz[i].type = 1;
}
int m;
cin >> m;
for(int i=1; i<=m; i++){
cin >> niz[i+n].c >> niz[i+n].f >> niz[i+n].v;
niz[i+n].type = -1;
}
sort(niz+1, niz+1+n+m, cmp);
ll sm = 0, smp = 0;
for(int i=1; i<=1e5; i++) dpp[i] = -1e15;
for(int i=1; i<=n+m; i++){
sm += max(niz[i].type*niz[i].c, 0LL);
for(int j=0; j<=sm; j++){
dp[j] = dpp[j];
if(j-niz[i].type*niz[i].c >= 0LL && j-niz[i].type*niz[i].c <= smp) dp[j] = max(dp[j], dpp[j-niz[i].type*niz[i].c] - niz[i].type*niz[i].v);
}
for(int j=0; j<=sm; j++) dpp[j] = dp[j];
smp = sm;
}
ll mx = 0;
for(int j=0; j<=sm; j++) mx = max(mx, dp[j]);
cout << mx;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1100 KB |
Output is correct |
2 |
Correct |
1 ms |
1100 KB |
Output is correct |
3 |
Correct |
1 ms |
1100 KB |
Output is correct |
4 |
Correct |
1 ms |
1084 KB |
Output is correct |
5 |
Correct |
2 ms |
1192 KB |
Output is correct |
6 |
Correct |
2 ms |
1100 KB |
Output is correct |
7 |
Correct |
3 ms |
1100 KB |
Output is correct |
8 |
Correct |
3 ms |
1100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1100 KB |
Output is correct |
2 |
Correct |
1 ms |
1100 KB |
Output is correct |
3 |
Correct |
1 ms |
1100 KB |
Output is correct |
4 |
Correct |
1 ms |
1100 KB |
Output is correct |
5 |
Correct |
18 ms |
1228 KB |
Output is correct |
6 |
Correct |
2 ms |
1100 KB |
Output is correct |
7 |
Correct |
85 ms |
1536 KB |
Output is correct |
8 |
Correct |
11 ms |
1228 KB |
Output is correct |
9 |
Correct |
149 ms |
1792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1100 KB |
Output is correct |
2 |
Correct |
1 ms |
1100 KB |
Output is correct |
3 |
Correct |
1 ms |
1088 KB |
Output is correct |
4 |
Correct |
1 ms |
1088 KB |
Output is correct |
5 |
Correct |
1 ms |
1100 KB |
Output is correct |
6 |
Correct |
1 ms |
1100 KB |
Output is correct |
7 |
Correct |
1 ms |
1100 KB |
Output is correct |
8 |
Correct |
1 ms |
1100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1100 KB |
Output is correct |
2 |
Correct |
1 ms |
1100 KB |
Output is correct |
3 |
Correct |
6 ms |
1100 KB |
Output is correct |
4 |
Correct |
2 ms |
1100 KB |
Output is correct |
5 |
Correct |
253 ms |
1656 KB |
Output is correct |
6 |
Correct |
458 ms |
1968 KB |
Output is correct |
7 |
Correct |
438 ms |
1960 KB |
Output is correct |
8 |
Correct |
452 ms |
1808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1100 KB |
Output is correct |
2 |
Correct |
1 ms |
1100 KB |
Output is correct |
3 |
Correct |
17 ms |
1228 KB |
Output is correct |
4 |
Correct |
7 ms |
1100 KB |
Output is correct |
5 |
Correct |
294 ms |
2040 KB |
Output is correct |
6 |
Correct |
445 ms |
1860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1100 KB |
Output is correct |
2 |
Correct |
1 ms |
1100 KB |
Output is correct |
3 |
Correct |
1 ms |
1100 KB |
Output is correct |
4 |
Correct |
1 ms |
1084 KB |
Output is correct |
5 |
Correct |
2 ms |
1192 KB |
Output is correct |
6 |
Correct |
2 ms |
1100 KB |
Output is correct |
7 |
Correct |
3 ms |
1100 KB |
Output is correct |
8 |
Correct |
3 ms |
1100 KB |
Output is correct |
9 |
Correct |
1 ms |
1100 KB |
Output is correct |
10 |
Correct |
1 ms |
1100 KB |
Output is correct |
11 |
Correct |
1 ms |
1100 KB |
Output is correct |
12 |
Correct |
1 ms |
1100 KB |
Output is correct |
13 |
Correct |
18 ms |
1228 KB |
Output is correct |
14 |
Correct |
2 ms |
1100 KB |
Output is correct |
15 |
Correct |
85 ms |
1536 KB |
Output is correct |
16 |
Correct |
11 ms |
1228 KB |
Output is correct |
17 |
Correct |
149 ms |
1792 KB |
Output is correct |
18 |
Correct |
1 ms |
1100 KB |
Output is correct |
19 |
Correct |
1 ms |
1100 KB |
Output is correct |
20 |
Correct |
1 ms |
1088 KB |
Output is correct |
21 |
Correct |
1 ms |
1088 KB |
Output is correct |
22 |
Correct |
1 ms |
1100 KB |
Output is correct |
23 |
Correct |
1 ms |
1100 KB |
Output is correct |
24 |
Correct |
1 ms |
1100 KB |
Output is correct |
25 |
Correct |
1 ms |
1100 KB |
Output is correct |
26 |
Correct |
1 ms |
1100 KB |
Output is correct |
27 |
Correct |
1 ms |
1100 KB |
Output is correct |
28 |
Correct |
6 ms |
1100 KB |
Output is correct |
29 |
Correct |
2 ms |
1100 KB |
Output is correct |
30 |
Correct |
253 ms |
1656 KB |
Output is correct |
31 |
Correct |
458 ms |
1968 KB |
Output is correct |
32 |
Correct |
438 ms |
1960 KB |
Output is correct |
33 |
Correct |
452 ms |
1808 KB |
Output is correct |
34 |
Correct |
1 ms |
1100 KB |
Output is correct |
35 |
Correct |
1 ms |
1100 KB |
Output is correct |
36 |
Correct |
17 ms |
1228 KB |
Output is correct |
37 |
Correct |
7 ms |
1100 KB |
Output is correct |
38 |
Correct |
294 ms |
2040 KB |
Output is correct |
39 |
Correct |
445 ms |
1860 KB |
Output is correct |
40 |
Correct |
19 ms |
1304 KB |
Output is correct |
41 |
Correct |
54 ms |
1332 KB |
Output is correct |
42 |
Correct |
7 ms |
1228 KB |
Output is correct |
43 |
Correct |
491 ms |
2040 KB |
Output is correct |
44 |
Correct |
526 ms |
2044 KB |
Output is correct |
45 |
Correct |
319 ms |
2044 KB |
Output is correct |
46 |
Correct |
3 ms |
1100 KB |
Output is correct |
47 |
Correct |
5 ms |
1228 KB |
Output is correct |
48 |
Correct |
5 ms |
1228 KB |
Output is correct |