#include <bits/stdc++.h>
#define st first
#define nd second
using lint = int64_t;
constexpr int mod = int(1e9) + 7;
constexpr int inf = 0x3f3f3f3f;
constexpr int ninf = 0xcfcfcfcf;
constexpr lint linf = 0x3f3f3f3f3f3f3f3f;
const long double pi = acosl(-1.0);
// Returns -1 if a < b, 0 if a = b and 1 if a > b.
int cmp_double(double a, double b = 0, double eps = 1e-9) {
return a + eps > b ? b + eps > a ? 0 : 1 : -1;
}
using namespace std;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n;
cin>>n;
vector<int>c(n), f(n), v(n);
for(int i=0;i<n;i++) cin>>c[i]>>f[i]>>v[i];
int q;
cin>>q;
c.resize(n+q);
f.resize(n+q);
v.resize(n+q);
for(int i=n;i<n+q;i++) cin>>c[i]>>f[i]>>v[i];
vector<pair<int, int>>e(n+q);
for(int i=0;i<n+q;i++) e[i] = {f[i], -i};
sort(e.rbegin(), e.rend());
const int ms = 100000;
vector<lint>dp(ms+2, -linf);
dp[0] = 0;
for(auto [_, i] : e){
i = -i;
if(i < n){
for(int j=ms-c[i];j>=0;j--){
if(dp[j] == -linf) continue;
dp[j+c[i]] = max(dp[j+c[i]], dp[j] - v[i]);
}
}
else{
for(int j=c[i];j<=ms;j++){
if(dp[j] == -linf) continue;
dp[j-c[i]] = max(dp[j-c[i]], dp[j] + v[i]);
}
}
}
lint ans = 0;
for(int j=0;j<=ms;j++) ans = max(ans, dp[j]);
cout<<ans<<"\n";
return 0;
}
/*
[ ]Leu o problema certo???
[ ]Ver se precisa de long long
[ ]Viu o limite dos fors (é n? é m?)
[ ]Tamanho do vetor, será que é 2e5 em vez de 1e5??
[ ]Testar sample
[ ]Testar casos de borda
[ ]1LL no 1LL << i
[ ]Testar mod (é 1e9+7, mesmo?, será que o mod não ficou negativo?)
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1108 KB |
Output is correct |
2 |
Correct |
1 ms |
1108 KB |
Output is correct |
3 |
Correct |
8 ms |
1040 KB |
Output is correct |
4 |
Correct |
15 ms |
1108 KB |
Output is correct |
5 |
Correct |
135 ms |
1108 KB |
Output is correct |
6 |
Correct |
133 ms |
1108 KB |
Output is correct |
7 |
Correct |
147 ms |
1108 KB |
Output is correct |
8 |
Correct |
151 ms |
1108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
2 ms |
1108 KB |
Output is correct |
3 |
Correct |
11 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 |
65 ms |
1108 KB |
Output is correct |
7 |
Correct |
187 ms |
1108 KB |
Output is correct |
8 |
Correct |
145 ms |
1108 KB |
Output is correct |
9 |
Correct |
206 ms |
1108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1108 KB |
Output is correct |
2 |
Correct |
3 ms |
1108 KB |
Output is correct |
3 |
Correct |
14 ms |
1108 KB |
Output is correct |
4 |
Correct |
14 ms |
1108 KB |
Output is correct |
5 |
Correct |
27 ms |
1108 KB |
Output is correct |
6 |
Correct |
27 ms |
1108 KB |
Output is correct |
7 |
Correct |
40 ms |
1108 KB |
Output is correct |
8 |
Correct |
35 ms |
1108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1108 KB |
Output is correct |
2 |
Correct |
2 ms |
1108 KB |
Output is correct |
3 |
Correct |
111 ms |
1108 KB |
Output is correct |
4 |
Correct |
125 ms |
1108 KB |
Output is correct |
5 |
Correct |
372 ms |
1236 KB |
Output is correct |
6 |
Correct |
448 ms |
1172 KB |
Output is correct |
7 |
Correct |
465 ms |
1236 KB |
Output is correct |
8 |
Correct |
447 ms |
1236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1108 KB |
Output is correct |
2 |
Correct |
12 ms |
1108 KB |
Output is correct |
3 |
Correct |
65 ms |
1108 KB |
Output is correct |
4 |
Correct |
141 ms |
1108 KB |
Output is correct |
5 |
Correct |
407 ms |
1108 KB |
Output is correct |
6 |
Correct |
468 ms |
1108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1108 KB |
Output is correct |
2 |
Correct |
1 ms |
1108 KB |
Output is correct |
3 |
Correct |
8 ms |
1040 KB |
Output is correct |
4 |
Correct |
15 ms |
1108 KB |
Output is correct |
5 |
Correct |
135 ms |
1108 KB |
Output is correct |
6 |
Correct |
133 ms |
1108 KB |
Output is correct |
7 |
Correct |
147 ms |
1108 KB |
Output is correct |
8 |
Correct |
151 ms |
1108 KB |
Output is correct |
9 |
Correct |
1 ms |
980 KB |
Output is correct |
10 |
Correct |
2 ms |
1108 KB |
Output is correct |
11 |
Correct |
11 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 |
65 ms |
1108 KB |
Output is correct |
15 |
Correct |
187 ms |
1108 KB |
Output is correct |
16 |
Correct |
145 ms |
1108 KB |
Output is correct |
17 |
Correct |
206 ms |
1108 KB |
Output is correct |
18 |
Correct |
3 ms |
1108 KB |
Output is correct |
19 |
Correct |
3 ms |
1108 KB |
Output is correct |
20 |
Correct |
14 ms |
1108 KB |
Output is correct |
21 |
Correct |
14 ms |
1108 KB |
Output is correct |
22 |
Correct |
27 ms |
1108 KB |
Output is correct |
23 |
Correct |
27 ms |
1108 KB |
Output is correct |
24 |
Correct |
40 ms |
1108 KB |
Output is correct |
25 |
Correct |
35 ms |
1108 KB |
Output is correct |
26 |
Correct |
2 ms |
1108 KB |
Output is correct |
27 |
Correct |
2 ms |
1108 KB |
Output is correct |
28 |
Correct |
111 ms |
1108 KB |
Output is correct |
29 |
Correct |
125 ms |
1108 KB |
Output is correct |
30 |
Correct |
372 ms |
1236 KB |
Output is correct |
31 |
Correct |
448 ms |
1172 KB |
Output is correct |
32 |
Correct |
465 ms |
1236 KB |
Output is correct |
33 |
Correct |
447 ms |
1236 KB |
Output is correct |
34 |
Correct |
1 ms |
1108 KB |
Output is correct |
35 |
Correct |
12 ms |
1108 KB |
Output is correct |
36 |
Correct |
65 ms |
1108 KB |
Output is correct |
37 |
Correct |
141 ms |
1108 KB |
Output is correct |
38 |
Correct |
407 ms |
1108 KB |
Output is correct |
39 |
Correct |
468 ms |
1108 KB |
Output is correct |
40 |
Correct |
82 ms |
1108 KB |
Output is correct |
41 |
Correct |
161 ms |
1116 KB |
Output is correct |
42 |
Correct |
209 ms |
1108 KB |
Output is correct |
43 |
Correct |
369 ms |
1236 KB |
Output is correct |
44 |
Correct |
369 ms |
1236 KB |
Output is correct |
45 |
Correct |
340 ms |
1236 KB |
Output is correct |
46 |
Correct |
143 ms |
1104 KB |
Output is correct |
47 |
Correct |
214 ms |
1108 KB |
Output is correct |
48 |
Correct |
208 ms |
1108 KB |
Output is correct |