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>
#define int long long
#define rep(i,n) for(int i = 0; i<n; i++)
#define all(a) a.begin(), a.end()
using namespace std;
signed main()
{
int n,m,x;
cin>>n;
int f[n], v[n];
rep(i,n) cin >> x >> f[i] >> v[i];
cin>>m;
int F[m], V[m];
rep(i,m) cin >> x >> F[i] >> V[i];
int dp[n][m];
rep(i,n)
{
rep(j,m)
{
dp[i][j] = 0;
if (i>0) dp[i][j] = max(dp[i][j], dp[i-1][j]);
if (j>0) dp[i][j] = max(dp[i][j], dp[i][j-1]);
if(i>0&&j>0&&f[i]>=F[j]) dp[i][j] = max(dp[i][j], dp[i-1][j-1] + V[i] - v[i]);
}
}
cout << dp[n-1][m-1] << "\n";
}
# | 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... |