# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
563804 | tqbfjotld | Two Dishes (JOI19_dishes) | C++14 | 218 ms | 103204 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 int long long
int n,m;
int A[1000005];
int S[1000005];
int P[1000005];
int B[1000005];
int T[1000005];
int Q[1000005];
int prefA[1000005];
int prefB[1000005];
int mem[2005][2005];
int dp(int a, int b){
if (mem[a][b]!=-1) return mem[a][b];
int ans = -999999999999999999LL;
if (a==0&&b==0) ans = 0;
if (a!=0){
int t = dp(a-1,b);
if (prefA[a]+prefB[b]<=S[a-1]){
t += P[a-1];
}
ans = max(ans,t);
}
if (b!=0){
int t = dp(a,b-1);
if (prefA[a]+prefB[b]<=T[b-1]){
t += Q[b-1];
}
ans = max(ans,t);
}
return mem[a][b] = ans;
}
main(){
scanf("%lld%lld",&n,&m);
for (int x = 0; x<n; x++){
scanf("%lld%lld%lld",&A[x],&S[x],&P[x]);
}
for (int x = 0; x<m; x++){
scanf("%lld%lld%lld",&B[x],&T[x],&Q[x]);
}
memset(mem,-1,sizeof(mem));
for (int x = 1; x<=n; x++){
prefA[x] = prefA[x-1]+A[x-1];
}
for (int x = 1; x<=m; x++){
prefB[x] = prefB[x-1]+B[x-1];
}
printf("%lld",dp(n,m));
}
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... |