#include <bits/stdc++.h>
#define For(i, a, b) for(int i = a; i <= b; i++)
#define Forr(i, a, b) for(int i = a; i >= b; i--)
#define F first
#define S second
#define sz(x) ((int)x.size())
#define all(x) x.begin(), x.end()
#define eb emplace_back
#define int LL
using namespace std;
using LL = long long;
using pii = pair<int, int>;
// const int MAXN = 1000010;
const int MAXN = 2010;
int a1[MAXN];
int s1[MAXN];
int p1[MAXN];
int pr1[MAXN];
int t1[MAXN];
int a2[MAXN];
int s2[MAXN];
int p2[MAXN];
int pr2[MAXN];
int t2[MAXN];
int su[MAXN][MAXN];
int dp[MAXN];
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
// NYA =^-w-^=
int n, m; cin >> n >> m;
assert(n <= MAXN);
For(i, 1, n) {
cin >> a1[i] >> s1[i] >> p1[i];
pr1[i] = pr1[i - 1] + a1[i];
}
For(i, 1, m) {
cin >> a2[i] >> s2[i] >> p2[i];
pr2[i] = pr2[i - 1] + a2[i];
}
For(i, 1, n) {
auto it = upper_bound(pr2, pr2 + m + 1, s1[i] - pr1[i]);
t1[i] = it - pr2 - 1;
// cout << i << " " << t1[i] << "\n";
}
For(i, 1, m) {
auto it = upper_bound(pr1, pr1 + n + 1, s2[i] - pr2[i]);
t2[i] = it - pr1 - 1;
// cout << i << " " << t2[i] << "\n";
For(j, 0, t2[i]) {
su[j][i]++;
}
}
For(i, 0, n) For(j, 1, m) su[i][j] += su[i][j - 1];
int ans = 0;
For(i, 1, n) if(t1[i] >= 0) {
int add = 0;
dp[i] = su[0][t1[i]];
Forr(i2, i - 1, 1) {
if(t1[i2] > t1[i]) add++;
else {
dp[i] = max(dp[i], dp[i - 1] + su[i2][t1[i]] - su[i2][t1[i2]] + add);
}
}
ans = max(ans, dp[i] + su[i][m] - su[i][t1[i]]);
}
cout << ans << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
468 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
468 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
468 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |