#include <bits/stdc++.h>
typedef long long ll;
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
int n, m;
std::cin >> n >> m;
std::vector<ll> a(n), s(n), p(n);
for (int i = 0; i < n; ++i) {
std::cin >> a[i] >> s[i] >> p[i];
}
std::vector<ll> b(m), t(m), q(m);
for (int i = 0; i < m; ++i) {
std::cin >> b[i] >> t[i] >> q[i];
}
std::vector<ll> p_a(n), p_b(m);
std::partial_sum(a.begin(), a.end(), p_a.begin());
std::partial_sum(b.begin(), b.end(), p_b.begin());
auto wt = [&](int i, int j) {
return (i == 0 ? 0 : p_a[i - 1]) + (j == 0 ? 0 : p_b[j - 1]);
};
std::vector dp(n + 1, std::vector<int>(m + 1));
// dp[i][j] = ans if you take i items from pile a, and j items from pile b
for (int i = 0; i <= n; ++i) {
for (int j = 0; j <= m; ++j) {
if (j != 0) {
dp[i][j] = std::max(dp[i][j], dp[i][j - 1] + (wt(i, j) <= t[j - 1]));
}
if (i != 0) {
dp[i][j] = std::max(dp[i][j], dp[i - 1][j] + (wt(i, j) <= s[i - 1]));
}
}
}
std::cout << dp[n][m] << '\n';
}
# | 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... |