제출 #1319076

#제출 시각아이디문제언어결과실행 시간메모리
1319076aaaaaaaaCloud Computing (CEOI18_clo)C++20
54 / 100
913 ms3608 KiB
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define int long long
vector<vector<int>> v;
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(nullptr); cout.tie(nullptr);
    int n, m, cores = 0; cin >> n;
    for(int i = 0, a, b, c; i < n; ++i){
        cin >> a >> b >> c;
        v.push_back({b, 0, a, c});
        cores += a;
    }
    cin >> m;
    for(int i = 0, a, b, c; i < m; ++i){
        cin >> a >> b >> c;
        v.push_back({b, 1, a, c});
        cores += a;
    }
    sort(all(v));
    vector<int> dp(cores + 51, 0);
    for(int i = 0; i < v.size(); ++i){
        vector<int> ndp(cores + 51, 0);
        for(int j = 0; j <= cores + 2; ++j){
            ndp[j] = dp[j];
            if(v[i][1] == 0){
                if(j + v[i][2] <= cores) ndp[j] = max(ndp[j], (int) dp[j + v[i][2]] - v[i][3]);
            }else{
                if(v[i][2] <= j){
                    ndp[j] = max(ndp[j], (int) dp[j - v[i][2]] + v[i][3]);
                }
            }
        }
        swap(dp, ndp);
    }
    cout << dp[0] << "\n";
    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...