// ~Be name khoda~ //
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define cl clear
#define endll '\n'
const int maxn = 1e6 + 10;
const int maxn5 = 2e3 + 5;
const int maxnt = 1.2e6 + 10;
const int maxn3 = 1e3 + 10;
const int mod = 1e9 + 7;
const ll inf = 1e18;
ll dp[2][maxn5][2][52];
int f[maxn5], c[maxn5], v[maxn5];
int F[maxn5], C[maxn5], V[maxn5];
int pero[maxn5], perc[maxn5];
inline bool cmpc(int a, int b){return f[a] < f[b];}
inline bool cmpo(int a, int b){return F[a] < F[b];}
int main()
{
int n, m;
scanf("%d", &n);
for(int i = 1; i <= n; i++) scanf("%d%d%d", &c[i], &f[i], &v[i]);
scanf("%d", &m);
for(int i = 1; i <= m; i++) scanf("%d%d%d", &C[i], &F[i], &V[i]);
for(int i = 1; i <= n; i++) perc[i] = i;
for(int i = 1; i <= m; i++) pero[i] = i;
sort(perc + 1, perc + n + 1, cmpc);
sort(pero + 1, pero + m + 1, cmpo);
for(int i = 1; i <= m; i++){
int now = i%2;
int last = now ^ 1;
for(int ty = 0; ty < 2; ty++) for(int rem = 0; rem < 50; rem++){
if(rem == 0 || ty == 1) dp[now][0][ty][rem] = 0;
else dp[now][0][ty][rem] = -1 * inf;
}
for(int j = 1; j <= n; j++) for(int ty = 0; ty < 2; ty++) for(int rem = 0; rem < 50; rem++){
ll ans = -1 * inf;
if(rem == 0){
ans = 0;
ans = max(ans, dp[last][j][ty][0]);
ans = max(ans, dp[now][j - 1][ty][0]);
if(F[pero[i]] <= f[perc[j]]){
if(C[pero[i]] > c[perc[j]]){
ans = max(ans, ll(V[pero[i]]) - v[perc[j]] + dp[now][j - 1][0][C[pero[i]] - c[perc[j]]]);
}
else if(C[pero[i]] < c[perc[j]]){
ans = max(ans, ll(V[pero[i]]) - v[perc[j]] + dp[last][j][1][c[perc[j]] - C[pero[i]]]);
}
else{
ans = max(ans, ll(V[pero[i]]) - v[perc[j]] + dp[last][j - 1][0][0]);
}
}
}
else if(ty == 0){
ans = max(ans, dp[now][j - 1][ty][rem]);
if(F[pero[i]] <= f[perc[j]]){
if(rem > c[perc[j]]){
ans = max(ans, dp[now][j - 1][0][rem - c[perc[j]]] - v[perc[j]]);
}
else if(rem < c[perc[j]]){
ans = max(ans, dp[last][j][1][c[perc[j]] - rem] - v[perc[j]]);
}
else{
ans = max(ans, dp[last][j - 1][0][0] - v[perc[j]]);
}
}
}
else if(ty == 1){
ans = max(ans, dp[now][j - 1][0][0]);
ans = max(ans, dp[last][j][1][rem]);
if(F[pero[i]] <= f[perc[j]]){
if(C[pero[i]] > rem){
ans = max(ans, V[pero[i]] + dp[now][j - 1][0][C[pero[i]] - rem]);
}
else if(C[pero[i]] < rem){
ans = max(ans, V[pero[i]] + dp[last][j][1][rem - C[pero[i]]]);
}
else{
ans = max(ans, V[pero[i]] + dp[last][j - 1][0][0]);
}
}
}
dp[now][j][ty][rem] = ans;
}
}
cout << dp[m%2][n][0][0] << endl;
}
Compilation message
clo.cpp: In function 'int main()':
clo.cpp:36:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
36 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
clo.cpp:37:35: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
37 | for(int i = 1; i <= n; i++) scanf("%d%d%d", &c[i], &f[i], &v[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:38:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
38 | scanf("%d", &m);
| ~~~~~^~~~~~~~~~
clo.cpp:39:35: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
39 | for(int i = 1; i <= m; i++) scanf("%d%d%d", &C[i], &F[i], &V[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
9 ms |
332 KB |
Output is correct |
6 |
Correct |
9 ms |
332 KB |
Output is correct |
7 |
Correct |
9 ms |
408 KB |
Output is correct |
8 |
Correct |
9 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
5 ms |
1740 KB |
Output is correct |
6 |
Correct |
4 ms |
1740 KB |
Output is correct |
7 |
Correct |
11 ms |
3532 KB |
Output is correct |
8 |
Correct |
12 ms |
3640 KB |
Output is correct |
9 |
Correct |
12 ms |
3512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
424 KB |
Output is correct |
4 |
Correct |
2 ms |
460 KB |
Output is correct |
5 |
Correct |
15 ms |
588 KB |
Output is correct |
6 |
Correct |
15 ms |
708 KB |
Output is correct |
7 |
Correct |
15 ms |
716 KB |
Output is correct |
8 |
Correct |
16 ms |
756 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
8 ms |
2788 KB |
Output is correct |
4 |
Correct |
9 ms |
396 KB |
Output is correct |
5 |
Correct |
1150 ms |
3580 KB |
Output is correct |
6 |
Correct |
1295 ms |
3592 KB |
Output is correct |
7 |
Correct |
1290 ms |
3676 KB |
Output is correct |
8 |
Correct |
1244 ms |
3508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
300 KB |
Output is correct |
2 |
Correct |
1 ms |
428 KB |
Output is correct |
3 |
Correct |
33 ms |
1228 KB |
Output is correct |
4 |
Correct |
331 ms |
1612 KB |
Output is correct |
5 |
Correct |
970 ms |
3592 KB |
Output is correct |
6 |
Correct |
1300 ms |
3652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
9 ms |
332 KB |
Output is correct |
6 |
Correct |
9 ms |
332 KB |
Output is correct |
7 |
Correct |
9 ms |
408 KB |
Output is correct |
8 |
Correct |
9 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
460 KB |
Output is correct |
12 |
Correct |
1 ms |
460 KB |
Output is correct |
13 |
Correct |
5 ms |
1740 KB |
Output is correct |
14 |
Correct |
4 ms |
1740 KB |
Output is correct |
15 |
Correct |
11 ms |
3532 KB |
Output is correct |
16 |
Correct |
12 ms |
3640 KB |
Output is correct |
17 |
Correct |
12 ms |
3512 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
2 ms |
424 KB |
Output is correct |
21 |
Correct |
2 ms |
460 KB |
Output is correct |
22 |
Correct |
15 ms |
588 KB |
Output is correct |
23 |
Correct |
15 ms |
708 KB |
Output is correct |
24 |
Correct |
15 ms |
716 KB |
Output is correct |
25 |
Correct |
16 ms |
756 KB |
Output is correct |
26 |
Correct |
0 ms |
332 KB |
Output is correct |
27 |
Correct |
0 ms |
332 KB |
Output is correct |
28 |
Correct |
8 ms |
2788 KB |
Output is correct |
29 |
Correct |
9 ms |
396 KB |
Output is correct |
30 |
Correct |
1150 ms |
3580 KB |
Output is correct |
31 |
Correct |
1295 ms |
3592 KB |
Output is correct |
32 |
Correct |
1290 ms |
3676 KB |
Output is correct |
33 |
Correct |
1244 ms |
3508 KB |
Output is correct |
34 |
Correct |
1 ms |
300 KB |
Output is correct |
35 |
Correct |
1 ms |
428 KB |
Output is correct |
36 |
Correct |
33 ms |
1228 KB |
Output is correct |
37 |
Correct |
331 ms |
1612 KB |
Output is correct |
38 |
Correct |
970 ms |
3592 KB |
Output is correct |
39 |
Correct |
1300 ms |
3652 KB |
Output is correct |
40 |
Correct |
72 ms |
1100 KB |
Output is correct |
41 |
Correct |
214 ms |
1484 KB |
Output is correct |
42 |
Correct |
552 ms |
2844 KB |
Output is correct |
43 |
Correct |
1255 ms |
3600 KB |
Output is correct |
44 |
Correct |
1264 ms |
3592 KB |
Output is correct |
45 |
Correct |
956 ms |
3532 KB |
Output is correct |
46 |
Correct |
237 ms |
1988 KB |
Output is correct |
47 |
Correct |
512 ms |
2884 KB |
Output is correct |
48 |
Correct |
500 ms |
2884 KB |
Output is correct |