Submission #320924

#TimeUsernameProblemLanguageResultExecution timeMemory
320924phathnvCloud Computing (CEOI18_clo)C++11
100 / 100
1379 ms2156 KiB
#include <bits/stdc++.h>

#define mp make_pair
#define X first
#define Y second
#define taskname "CloudComputing"

using namespace std;

typedef long long ll;
typedef pair <int, int> ii;

const int C = 100001;
const ll INF = 1e18;

struct order{
    int type; /// 0 buy, 1: sell
    int c, f, v;
    order(int _t, int _c, int _f, int _v){
        type = _t;
        c = _c;
        f = _f;
        v = _v;
    }
};

int n, m;
ll dp[C], nxtDp[C];
vector <order> ords;

void readInput(){
    cin >> n;
    for(int i = 1; i <= n; i++){
        int c, f, v;
        cin >> c >> f >> v;
        ords.push_back(order(0, c, f, -v));
    }
    cin >> m;
    for(int i = 1; i <= m; i++){
        int c, f, v;
        cin >> c >> f >> v;
        ords.push_back(order(1, -c, f, v));
    }
}

void solve(){
    sort(ords.begin(), ords.end(), [](const order &a, const order &b){
            if (a.f != b.f)
                return a.f > b.f;
            return a.type < b.type;
        });

    dp[0] = 0;
    for(int i = 1; i < C; i++)
        dp[i] = -INF;
    for(order o : ords){
        int c = o.c;
        int v = o.v;
        for(int i = 0; i < C; i++)
            nxtDp[i] = -INF;
        for(int i = 0; i < C; i++){
            nxtDp[i] = max(nxtDp[i], dp[i]);
            if (0 <= i + c && i + c < C)
                nxtDp[i + c] = max(nxtDp[i + c], dp[i] + v);
        }
        for(int i = 0; i < C; i++)
            swap(dp[i], nxtDp[i]);
    }
    ll res = -1;
    for(int i = 0; i < C; i++)
        res = max(res, dp[i]);
    cout << res;
}

int main(){
    if (fopen(taskname".inp", "r")){
        freopen(taskname".inp", "r", stdin);
        freopen(taskname".out", "w", stdout);
    }
    readInput();
    solve();
    return 0;
}

Compilation message (stderr)

clo.cpp: In function 'int main()':
clo.cpp:77:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   77 |         freopen(taskname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:78:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   78 |         freopen(taskname".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...