제출 #361761

#제출 시각아이디문제언어결과실행 시간메모리
361761ritul_kr_singhCloud Computing (CEOI18_clo)C++14
100 / 100
2157 ms7020 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int, int>
#define clock first
#define core second.first
#define price second.second

signed main(){
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    int n, m; cin >> n;
    vector<pair<int, pii>> comps; // clock rate, {core, price}
    pair<int, pii> ii;
    for(int j=0; j<n; ++j){
        cin >> ii.core >> ii.clock >> ii.price;
        ii.price = -ii.price;
        comps.push_back(ii);
    }
    cin >> m;
    for(int j=0; j<m; ++j){
        cin >> ii.core >> ii.clock >> ii.price;
        ii.core = -ii.core;
        comps.push_back(ii);
    }
    sort(comps.begin(), comps.end(), greater<>());
    n += m;
    int lim=(n)*50;
    int dp[2][lim+lim+1];
    int ind = 1;
    for(int i=0; i<2; ++i){
        for(int j=0; j<=lim; ++j){
            dp[i][j] = -1e18;
        }
        dp[i][lim] = 0;
        for(int j=1; j<=lim; ++j){
            dp[i][lim+j] = -1e18;
        }
    }
    int ans = -1e18;
    for(int x=1; x<=n; ++x){
        ind = 1-ind;
        int i = ind;
        auto curr = comps[x-1];
        for(int j=0; j<=lim+lim; ++j){
            dp[i][j] = dp[!i][j];
        }
        if(curr.core>=0){
            for(int j=lim+curr.core; j<=lim+lim; ++j){
                if(dp[!i][j-curr.core]>(int)-1e18)
                    dp[i][j] = max(dp[i][j], dp[!i][j-curr.core]+curr.price);
            }
        }else{
            curr.core = -curr.core;
            for(int j=lim+lim-curr.core; j+curr.core>=lim; --j){
                if(dp[!i][j+curr.core]>(int)-1e18)
                    dp[i][j] = max(dp[i][j], dp[!i][j+curr.core]+curr.price);
            }
        }
    }
    for(int j=0; j<=lim; ++j){
//        cout << dp[n][j+lim] << " ";
        ans = max(ans, dp[ind][j+lim]);
    }
//    cout << "\n";
    cout << ans << "\n";
}
#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...