Submission #1273089

#TimeUsernameProblemLanguageResultExecution timeMemory
1273089zuzuCloud Computing (CEOI18_clo)C++20
0 / 100
3091 ms3572 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const ll INF = 1e18;
const int maxn = 1e5;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n; cin >> n;
    vector <ll> dp(maxn+1, INF), dp2(maxn+1, -1), prev(maxn+1, INF), prev2(maxn+1, -1);
    dp[0] = 0;
    prev[0] = 0;
    dp2[0] = 0;
    prev2[0] = 0;
    for(int i = 0; i < n; i++){
        int c, f, v; cin >> c >> f >> v;
        for(int j = c; j <= maxn; j++){
            if(prev[j-c] != INF) dp[j] = min(dp[j], prev[j-c] + v);
        }
        prev = dp;
    }
    int m; cin >> m;
    for(int i = 0; i < m; i++){
        int c, f, v; cin >> c >> f >> v;
        for(int j = c; j <= maxn; j++){
            if(prev2[j-c] != -1) dp2[j] = max(dp2[j], prev2[j-c] + v);
        }
        prev2 = dp2;
    }
    ll ans = 0;
    for(int i = 1; i <= maxn; i++){
        for(int j = 1; j <= i; j++){
            ans = max(ans, dp2[j] - dp[i]);
        }
    }
    cout << ans;
    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...