# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
578399 | Johann | Two Dishes (JOI19_dishes) | C++14 | 536 ms | 1048576 KiB |
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>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define tiii tuple<int,int,int>
#define vi vector<ll>
#define vpii vector<pii>
#define vtiii vector<tiii>
#define vvi vector<vi>
#define sz(x) (int) (x).size()
#define all(x) (x).begin(), (x).end()
const int MAXN = 1e6 + 7;
ll N,M;
ll A[MAXN],B[MAXN],S[MAXN],T[MAXN],P[MAXN],Q[MAXN];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> N >> M;
for (int i = 0; i < N; ++i) cin >> A[i] >> S[i] >> P[i];
for (int i = 0; i < M; ++i) cin >> B[i] >> T[i] >> Q[i];
ll total = accumulate(A, A+N, 0) + accumulate(B, B+M, 0);
ll ans = 0;
int a = N-1, b = M-1;
vvi sums(N+1, vi(M+1, 0));
vvi dp(N+1, vi(M+1, 0));
for (int n = 0; n < N; ++n) {
sums[n+1][0] = sums[n][0] + A[n];
dp[n+1][0] = dp[n][0];
if (sums[n+1][0] <= S[n]) dp[n+1][0] += P[n];
}
for (int m = 0; m < M; ++m) {
sums[0][m+1] = sums[0][m] + B[m];
dp[0][m+1] = dp[0][m];
if (sums[0][m+1] <= T[m]) dp[0][m+1] += Q[m];
}
for (int n = 1; n <= N; ++n) {
for (int m = 1; m <= M; ++m) {
sums[n][m] = sums[n-1][m] + A[n-1];
ll pa = dp[n-1][m];
pa += (sums[n][m] <= S[n-1]) ? P[n-1] : 0;
ll pb = dp[n][m-1];
pb += (sums[n][m] <= T[m-1]) ? Q[m-1] : 0;
dp[n][m] = max(pa, pb);
}
}
cout << dp[N][M] << "\n";
}
Compilation message (stderr)
# | 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... |