제출 #1273097

#제출 시각아이디문제언어결과실행 시간메모리
1273097zuzuCloud Computing (CEOI18_clo)C++20
18 / 100
375 ms3580 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++){
        dp2[i] = max(dp2[i], dp2[i-1]);
    }
    for(int i = 1; i <= maxn; i++){
        ans = max(ans, dp2[i] - 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...