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 ll long long
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ld long double
#define sz(a) ((ll)(a).size())
using namespace std;
const ll maxn=2005, inf=1e18;
ll a[maxn], s[maxn], p[maxn], b[maxn], t[maxn], q[maxn];
ll dp[maxn][maxn];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
ll n, m; cin >> n >> m;
if (n>2000) exit(0);
for (ll i=1; i<=n; i++) cin >> a[i] >> s[i] >> p[i], a[i]+=a[i-1];
for (ll i=1; i<=m; i++) cin >> b[i] >> t[i] >> q[i], b[i]+=b[i-1];
for (ll i=0; i<=n; i++)
for (ll j=0; j<=m; j++)
dp[i][j]=-inf;
for (ll i=0; i<=n; i++) for (ll j=0; j<=m; j++)
{
if (i==0 && j==0) dp[i][j]=0;
if (i) dp[i][j]=max(dp[i][j], dp[i-1][j]+(a[i]+b[j]<=s[i]?p[i]:0));
if (j) dp[i][j]=max(dp[i][j], dp[i][j-1]+(a[i]+b[j]<=t[j]?q[j]:0));
}
cout << dp[n][m];
}
# | 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... |