제출 #1176351

#제출 시각아이디문제언어결과실행 시간메모리
1176351avighnaTwo Dishes (JOI19_dishes)C++20
10 / 100
555 ms1114112 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...