# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
374178 | Mamnoon_Siam | Two Dishes (JOI19_dishes) | C++17 | 4 ms | 876 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;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
#define all(v) begin(v), end(v)
#define sz(v) (int)(v).size()
#define fi first
#define se second
const int N = 2e3 + 3;
int n, m;
ll A[N], B[N], S[N], T[N], P[N], Q[N];
ll donburi[N][N], curry[N][N];
ll donburi_p[N][N], curry_p[N][N];
ll dp[N][N];
int main(int argc, char const *argv[])
{
#ifdef LOCAL
freopen("in", "r", stdin);
#endif
scanf("%d %d", &n, &m);
for(int i = 1; i <= n; ++i) {
scanf("%lld %lld %lld", &A[i], &S[i], &P[i]);
}
for(int i = 1; i <= m; ++i) {
scanf("%lld %lld %lld", &B[i], &T[i], &Q[i]);
}
for(ll i = 1, sum = 0; i <= n; ++i) {
sum += A[i];
if(sum <= S[i]) {
int j = 0;
ll sum2 = 0;
while(j < m and sum + sum2 + B[j+1] <= S[i]) {
sum2 += B[++j];
}
donburi[i][j] = P[i];
}
}
for(ll i = 1, sum = 0; i <= m; ++i) {
sum += B[i];
if(sum <= T[i]) {
int j = 0;
ll sum2 = 0;
while(j < n and sum + sum2 + A[j+1] <= T[i]) {
sum2 += B[++j];
}
curry[j][i] = Q[i];
}
}
for(int i = 0; i <= n; ++i) {
curry_p[i][0] = curry[i][0];
for(int j = 1; j <= m; ++j)
curry_p[i][j] = curry_p[i][j-1] + curry[i][j];
donburi_p[i][m] = donburi[i][m];
for(int j = m-1; j >= 0; --j) {
donburi_p[i][j] = donburi_p[i][j+1] + donburi[i][j];
}
}
function<void(ll&,ll)> chkmax = [](ll& x, ll y) {
x = max(x, y);
};
for(int x = 0; x <= n; ++x) {
for(int y = 0; y <= m; ++y) {
chkmax(dp[x+1][y], curry_p[x+1][y] + donburi_p[x+1][y] + dp[x][y]);
chkmax(dp[x][y+1], curry[x][y+1] + dp[x][y]);
}
}
printf("%lld\n", dp[n][m]);
return 0;
}
/*
* use std::array instead of std::vector, if u can
* overflow?
* array bounds
*/
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... |