제출 #1284381

#제출 시각아이디문제언어결과실행 시간메모리
1284381tntCloud Computing (CEOI18_clo)C++20
100 / 100
254 ms1472 KiB
#include <bits/stdc++.h>
using namespace std;

#define pb push_back                    
#define ll long long 
#define S second
#define pb push_back
#define F first
#define int long long
const long long inf = 2e9 + 7;
const int N = 1e5 + 101;
int dp[N];
void solve(){     
    int n;
    cin>>n;
    vector<array<int, 4>>V;
    for(int i = 1; i <= n; i++){
        int c, f, v;
        cin>>c>>f>>v;
        V.pb({f, 1, c, v});
    }
    int m;
    cin>>m;
    for(int i = 1; i <= m; i++){
        int c, f, v;
        cin>>c>>f>>v;
        V.pb({f, 0, c, v});
    }
    for(int i = 1; i < N; i++){
        dp[i] = -1e18;
    }
    sort(V.begin(), V.end()); 
    reverse(V.begin(), V.end());
    for(auto [f, type, c, cost] : V){
        if(type == 1){
            for(int j = N - c - 1; j >= 0; j--){
                dp[j + c] = max(dp[j + c], dp[j] - cost); 
            }
        }
        else{
            for(int j = 0; j + c < N; j++){
                dp[j] = max(dp[j], dp[j + c] + cost);
            }
        }
    }
    int ans = 0;
    for(int i = 0; i < N; i++) ans = max(ans, dp[i]);
    cout<<ans;
}
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    //freopen("promote.in", "r", stdin);
    //freopen("promote.out", "w", stdout);
    int t = 1;
    while(t--){
     	solve();
    }
}
#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...