Submission #1216979

#TimeUsernameProblemLanguageResultExecution timeMemory
1216979Ahmed_KaanicheTwo Dishes (JOI19_dishes)C++20
10 / 100
578 ms1114112 KiB
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define fi first
#define se second
#define pb push_back
#define endl "\n"


int main() {
    //the booster of input and output
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    
    //the body
    ll n, m;
    cin >> n >> m;
    vector<pair<ll, pair<ll, ll>>> arr1(n + 1, {0, {0, 0}});
    vector<pair<ll, pair<ll, ll>>> arr2(m + 1, {0, {0, 0}});
    vector<ll> pref1(n + 1, 0);
    vector<ll> pref2(m + 1, 0);
    
    
    for (ll i = 1; i <= n; ++i) {
        cin >> arr1[i].fi >> arr1[i].se.fi >> arr1[i].se.se;
        pref1[i] = pref1[i - 1] + arr1[i].fi;
    }
    for (ll i = 1; i <= m; ++i) {
        cin >> arr2[i].fi >> arr2[i].se.fi >> arr2[i].se.se;
        pref2[i] = pref2[i - 1] + arr2[i].fi;
    }
    
    vector<vector<ll>> dp(n + 1, vector<ll>(m + 1, 0));
    
    for (ll i = 0; i <= n; ++i) {
        for (ll j = 0; j <= m; ++j) {
            if (i >= 1) {
                if (pref1[i] + pref2[j] <= arr1[i].se.fi)
                    dp[i][j] = max(dp[i][j], dp[i-1][j] + arr1[i].se.se);
                else
                    dp[i][j] = max(dp[i][j], dp[i-1][j]);
            }
            if (j >= 1) {
                if (pref1[i] + pref2[j] <= arr2[j].se.fi)
                    dp[i][j] = max(dp[i][j], dp[i][j - 1] + arr2[j].se.se);
                else
                    dp[i][j] = max(dp[i][j], dp[i][j - 1]);
            }
        }
    }
    cout << dp[n][m] << endl;
    
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...