This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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];
int dp2[MAXN][MAXN];
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
// NYA =^-w-^=
int n, m;
// #define QWQ
#ifndef QWQ
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];
}
#else
mt19937 rng(48763);
n = m = 5;
For(i, 1, n) {
a1[i] = rng() % 10 + 1;
s1[i] = rng() % 100 + 1;
p1[i] = 1;
pr1[i] = pr1[i - 1] + a1[i];
}
For(i, 1, m) {
a2[i] = rng() % 10 + 1;
s2[i] = rng() % 100 + 1;
p2[i] = 1;
pr2[i] = pr2[i - 1] + a2[i];
}
#endif
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";
// dp2[i][0] = dp2[i - 1][0] + (t1[i] >= 0);
}
// cout << "\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";
// dp2[0][i] = dp2[0][i - 1] + (t2[i] >= 0);
For(j, 0, t2[i]) {
su[j][i]++;
}
}
// cout << "\n";
// For(i, 1, n) For(j, 1, m) {
// dp2[i][j] = max(dp2[i - 1][j] + (j <= t1[i]), dp2[i][j - 1] + (i <= t2[j]));
// }
// For(i, 0, n) For(j, 0, m) cout << dp2[i][j] << " \n"[j == m];
// cout << "\n";
// cout << dp[n][m] << "\n";
For(i, 0, n) For(j, 1, m) su[i][j] += su[i][j - 1];
int ans = su[0][m];
For(i, 1, n) if(t1[i] >= 0) {
int add = 0;
// dp[i] = su[0][t1[i]] + 1;
dp[i] = 0;
Forr(i2, i - 1, 1) if(t1[i2] >= 0) {
if(t1[i2] > t1[i]) add++;
else {
dp[i] = max(dp[i], dp[i2] + su[i2][t1[i]] - su[i2][t1[i2]] + add + 1);
}
}
dp[i] = max(dp[i], su[0][t1[i]] + add + 1);
// cout << i << " " << dp[i] << "\n";
ans = max(ans, dp[i] + su[i][m] - su[i][t1[i]]);
// cout << dp[i] << " " << dp2[i][t1[i]] << endl;
// assert(dp[i] == dp2[i][t1[i]]);
}
cout << ans << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |