#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define pii pair<int, int>
#define ppi pair<pii, int>
#define pip pair<int, pii>
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, n+1)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define SZ(x) (int)((x).size())
const ll maxn = 2005;
const ll inf = (1ll<<60);
const ll mod = 1e9+7;
int n, m;
int dp[maxn][maxn];
signed main(){
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin>>n>>m;
vector<int> a(n+1), s(n+1), p(n+1);
vector<int> b(m+1), t(m+1), q(m+1);
REP1(i, n) cin>>a[i]>>s[i]>>p[i];
REP1(j, m) cin>>b[j]>>t[j]>>q[j];
REP1(i, n) a[i] += a[i-1];
REP1(j, m) b[j] += b[j-1];
if (n > 2000 || m > 2000){
REP1(i, n) p[i] += p[i-1];
REP1(j, m) q[j] += q[j-1];
int k = s[1];
int mx = -inf;
int tot = 0;
REP(i, n+1){
if (a[i] <= k) tot = p[i];
int id = upper_bound(ALL(b), k-a[i]) - b.begin();
id = max(0ll, id-1);
mx = max(mx, q[id] + tot);
}
tot = 0;
REP(i, m+1){
if (b[i] <= k) tot = q[i];
int id = upper_bound(ALL(a), k-b[i]) - a.begin();
id = max(0ll, id-1);
mx = max(mx, p[id] + tot);
}
cout<<mx<<endl;
return 0;
}
REP(i, n+1){
REP(j, m+1){
if (i > 0) dp[i][j] = max(dp[i][j], dp[i-1][j] + (a[i]+b[j] <= s[i]));
if (j > 0) dp[i][j] = max(dp[i][j], dp[i][j-1] + (a[i]+b[j] <= t[j]));
}
}
cout<<dp[n][m]<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
115 ms |
9856 KB |
Output is correct |
2 |
Correct |
114 ms |
9700 KB |
Output is correct |
3 |
Correct |
106 ms |
9856 KB |
Output is correct |
4 |
Correct |
110 ms |
9704 KB |
Output is correct |
5 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
596 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
596 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
432 KB |
Output is correct |
17 |
Correct |
27 ms |
31828 KB |
Output is correct |
18 |
Correct |
27 ms |
31804 KB |
Output is correct |
19 |
Correct |
27 ms |
31836 KB |
Output is correct |
20 |
Correct |
26 ms |
31832 KB |
Output is correct |
21 |
Correct |
27 ms |
30612 KB |
Output is correct |
22 |
Correct |
27 ms |
31828 KB |
Output is correct |
23 |
Correct |
28 ms |
31728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
596 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
432 KB |
Output is correct |
17 |
Correct |
27 ms |
31828 KB |
Output is correct |
18 |
Correct |
27 ms |
31804 KB |
Output is correct |
19 |
Correct |
27 ms |
31836 KB |
Output is correct |
20 |
Correct |
26 ms |
31832 KB |
Output is correct |
21 |
Correct |
27 ms |
30612 KB |
Output is correct |
22 |
Correct |
27 ms |
31828 KB |
Output is correct |
23 |
Correct |
28 ms |
31728 KB |
Output is correct |
24 |
Incorrect |
90 ms |
9860 KB |
Output isn't correct |
25 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
596 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
432 KB |
Output is correct |
17 |
Correct |
27 ms |
31828 KB |
Output is correct |
18 |
Correct |
27 ms |
31804 KB |
Output is correct |
19 |
Correct |
27 ms |
31836 KB |
Output is correct |
20 |
Correct |
26 ms |
31832 KB |
Output is correct |
21 |
Correct |
27 ms |
30612 KB |
Output is correct |
22 |
Correct |
27 ms |
31828 KB |
Output is correct |
23 |
Correct |
28 ms |
31728 KB |
Output is correct |
24 |
Incorrect |
90 ms |
9860 KB |
Output isn't correct |
25 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
596 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
432 KB |
Output is correct |
17 |
Correct |
27 ms |
31828 KB |
Output is correct |
18 |
Correct |
27 ms |
31804 KB |
Output is correct |
19 |
Correct |
27 ms |
31836 KB |
Output is correct |
20 |
Correct |
26 ms |
31832 KB |
Output is correct |
21 |
Correct |
27 ms |
30612 KB |
Output is correct |
22 |
Correct |
27 ms |
31828 KB |
Output is correct |
23 |
Correct |
28 ms |
31728 KB |
Output is correct |
24 |
Incorrect |
90 ms |
9860 KB |
Output isn't correct |
25 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
115 ms |
9856 KB |
Output is correct |
2 |
Correct |
114 ms |
9700 KB |
Output is correct |
3 |
Correct |
106 ms |
9856 KB |
Output is correct |
4 |
Correct |
110 ms |
9704 KB |
Output is correct |
5 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
115 ms |
9856 KB |
Output is correct |
2 |
Correct |
114 ms |
9700 KB |
Output is correct |
3 |
Correct |
106 ms |
9856 KB |
Output is correct |
4 |
Correct |
110 ms |
9704 KB |
Output is correct |
5 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |