#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define sp " "
#define endl "\n"
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define pii pair<int, int>
#define st first
#define nd second
#define pb push_back
#define N 2005
#define L(node) node * 2
#define R(node) node * 2 + 1
#define int long long
#define M 51
int dp[2][N][M][2];
array<int, 3> cust[N], comp[N];
const int INF = 2e18 + 7;
int32_t main()
{
fastio();
int n;
cin>>n;
for (int i = 1; i <= n; i++)
cin>>comp[i][1]>>comp[i][0]>>comp[i][2];
int m;
cin>>m;
for (int i = 1; i <= m; i++)
cin>>cust[i][1]>>cust[i][0]>>cust[i][2];
sort(comp + 1, comp + 1 + n);
sort(cust + 1, cust + 1 + m);
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
for (int l = 1; l >= 0; l--)
{
for (int k = 0; k < M; k++)
{
int t1 = -INF, t2 = -INF, t3 = -INF, t4 = -INF;
t1 = dp[1][j - 1][k][l];
t3 = dp[0][j][k][0];
if (l == 0 && k + comp[i][1] >= cust[j][1] && k + comp[i][1] - cust[j][1] < M && comp[i][0] >= cust[j][0])
t2 = dp[1][j - 1][k + comp[i][1] - cust[j][1]][1] - comp[i][2] + cust[j][2];
if (l == 0 && k + comp[i][1] < M)
t2 = max(t2, dp[1][j][k + comp[i][1]][1] - comp[i][2]);
if (k >= cust[j][1] && comp[i][0] >= cust[j][0])
t4 = dp[1][j - 1][k - cust[j][1]][l] + cust[j][2];
int ans = max(t1, t2);
ans = max(ans, t3);
ans = max(ans, t4);
dp[1][j][k][l] = ans;
}
}
}
for (int j = 1; j <= m; j++)
{
for (int l = 1; l >=0; l--)
{
for (int k = 0; k < M; k++)
dp[0][j][k][l] = dp[1][j][k][l];
}
}
}
cout<<dp[0][m][0][0]<<endl;
cerr<<"time taken : "<<(float)clock() / CLOCKS_PER_SEC<<" seconds\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
588 KB |
Output is correct |
5 |
Correct |
16 ms |
3440 KB |
Output is correct |
6 |
Correct |
16 ms |
3412 KB |
Output is correct |
7 |
Correct |
15 ms |
3624 KB |
Output is correct |
8 |
Correct |
19 ms |
3596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
3 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
6 ms |
468 KB |
Output is correct |
6 |
Correct |
6 ms |
340 KB |
Output is correct |
7 |
Correct |
14 ms |
340 KB |
Output is correct |
8 |
Correct |
20 ms |
340 KB |
Output is correct |
9 |
Correct |
13 ms |
428 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
4 ms |
468 KB |
Output is correct |
4 |
Correct |
4 ms |
468 KB |
Output is correct |
5 |
Correct |
23 ms |
464 KB |
Output is correct |
6 |
Correct |
19 ms |
464 KB |
Output is correct |
7 |
Correct |
74 ms |
752 KB |
Output is correct |
8 |
Correct |
26 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
9 ms |
340 KB |
Output is correct |
4 |
Correct |
14 ms |
3164 KB |
Output is correct |
5 |
Correct |
1435 ms |
3288 KB |
Output is correct |
6 |
Correct |
1661 ms |
3644 KB |
Output is correct |
7 |
Correct |
1651 ms |
3668 KB |
Output is correct |
8 |
Correct |
1555 ms |
3620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
7 ms |
468 KB |
Output is correct |
3 |
Correct |
58 ms |
740 KB |
Output is correct |
4 |
Correct |
446 ms |
2304 KB |
Output is correct |
5 |
Correct |
1636 ms |
3676 KB |
Output is correct |
6 |
Correct |
1555 ms |
3628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
588 KB |
Output is correct |
5 |
Correct |
16 ms |
3440 KB |
Output is correct |
6 |
Correct |
16 ms |
3412 KB |
Output is correct |
7 |
Correct |
15 ms |
3624 KB |
Output is correct |
8 |
Correct |
19 ms |
3596 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
3 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
6 ms |
468 KB |
Output is correct |
14 |
Correct |
6 ms |
340 KB |
Output is correct |
15 |
Correct |
14 ms |
340 KB |
Output is correct |
16 |
Correct |
20 ms |
340 KB |
Output is correct |
17 |
Correct |
13 ms |
428 KB |
Output is correct |
18 |
Correct |
1 ms |
328 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
4 ms |
468 KB |
Output is correct |
21 |
Correct |
4 ms |
468 KB |
Output is correct |
22 |
Correct |
23 ms |
464 KB |
Output is correct |
23 |
Correct |
19 ms |
464 KB |
Output is correct |
24 |
Correct |
74 ms |
752 KB |
Output is correct |
25 |
Correct |
26 ms |
724 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
9 ms |
340 KB |
Output is correct |
29 |
Correct |
14 ms |
3164 KB |
Output is correct |
30 |
Correct |
1435 ms |
3288 KB |
Output is correct |
31 |
Correct |
1661 ms |
3644 KB |
Output is correct |
32 |
Correct |
1651 ms |
3668 KB |
Output is correct |
33 |
Correct |
1555 ms |
3620 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
7 ms |
468 KB |
Output is correct |
36 |
Correct |
58 ms |
740 KB |
Output is correct |
37 |
Correct |
446 ms |
2304 KB |
Output is correct |
38 |
Correct |
1636 ms |
3676 KB |
Output is correct |
39 |
Correct |
1555 ms |
3628 KB |
Output is correct |
40 |
Correct |
140 ms |
1108 KB |
Output is correct |
41 |
Correct |
390 ms |
2264 KB |
Output is correct |
42 |
Correct |
1063 ms |
2820 KB |
Output is correct |
43 |
Correct |
1962 ms |
3668 KB |
Output is correct |
44 |
Correct |
1727 ms |
3668 KB |
Output is correct |
45 |
Correct |
1446 ms |
3688 KB |
Output is correct |
46 |
Correct |
455 ms |
2004 KB |
Output is correct |
47 |
Correct |
991 ms |
2832 KB |
Output is correct |
48 |
Correct |
1142 ms |
2728 KB |
Output is correct |