This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define ll long long
#define ull unsigned ll
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin>>n>>m;
vector<ll> a(n);
vector<ll> s(n);
vector<ll> p(n);
for(int i = 0; i < n; i++)
{
cin>>a[i]>>s[i]>>p[i];
}
vector<ll> b(m);
vector<ll> t(m);
vector<ll> q(m);
for(int i = 0; i < m; i++)
{
cin>>b[i]>>t[i]>>q[i];
}
vector<ll> prea(n);
prea[0] = a[0];
for(int i = 1; i < n; i++)
{
prea[i] = prea[i-1]+a[i];
}
vector<ll> preb(m);
preb[0] = b[0];
for(int i = 1; i < m; i++)
{
preb[i] = preb[i-1]+b[i];
}
vector<vector<ll>> dp(n+1, vector<ll> (m+1, 0));
for(int i = 0; i <= n; i++)
{
for(int j = 0; j <= m; j++)
{
ll time = 0;
if(i > 0)
{
time += prea[i-1];
}
if(j > 0)
{
time += preb[j-1];
}
//Dish 1:
if(i > 0)
{
ll score = dp[i-1][j];
if(time <= s[i-1])
{
score += p[i-1];
}
dp[i][j] = max(dp[i][j], score);
}
if(j > 0)
{
ll score = dp[i][j-1];
if(time <= t[j-1])
{
score += q[j-1];
}
dp[i][j] = max(dp[i][j], score);
}
}
}
cout<<dp[n][m]<<"\n";
return 0;
}
# | 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... |