Submission #1303185

#TimeUsernameProblemLanguageResultExecution timeMemory
1303185dex111222333444555Cloud Computing (CEOI18_clo)C++20
72 / 100
526 ms2156 KiB
#include <bits/stdc++.h>
#define all(v) begin(v), end(v)
#define siz(v) (int)(v).size()
using namespace std;

template<class X, class Y> bool maximize(X &x, const Y &y){return x < y ? x = y, 1: 0;}

const int MAXN = 2005, mod = 1e9 + 7, infINT = 1e9 + 23443;
const long long inf = 1e18 + 2;

struct com{
    int c, f, v, id;
    bool type;

    com(int _c = 0, int _f = infINT, int _v = 0, int _id = 0, bool _type = 0):
        c(_c), f(_f), v(_v), id(_id), type(_type) {};

    bool operator<(const com &other){
        return f > other.f;
    }
};

int numCom, numQuery;
long long dp[2][MAXN * 50];
vector<com> vals;

void input(){
    vals.push_back(com());

    cin >> numCom;
    for(int i = 1; i <= numCom; i++){
        int c, f, v; cin >> c >> f >> v;
        vals.push_back(com(c, f, v, i, 0));
    }

    cin >> numQuery;
    for(int q = 1; q <= numQuery; q++){
        int c, f, v; cin >> c >> f >> v;
        vals.push_back(com(c, f, v, q, 1));
    }
}

void solve(){
    sort(all(vals));

    memset(dp[0], -0x3f, sizeof dp[0]);
    int nxt = 0, cur = 1, cnt = 0;
    dp[0][0] = 0;
    for(int i = 0; i < siz(vals) - 1; i++){
        swap(cur, nxt);
        memset(dp[nxt], -0x3f, sizeof dp[nxt]);
        for(int sum = 0; sum < MAXN * 50; sum++) if (dp[cur][sum] > -inf) {
            // do not choose
            maximize(dp[nxt][sum], dp[cur][sum]);
            // choose nxt
            if (vals[i + 1].type == 0 && sum + vals[i + 1].c < MAXN * 50){
                maximize(dp[nxt][sum + vals[i + 1].c], dp[cur][sum] - vals[i + 1].v);
            }
            if (vals[i + 1].type == 1 && sum >= vals[i + 1].c){
                maximize(dp[nxt][sum - vals[i + 1].c], dp[cur][sum] + vals[i + 1].v);
            }
        }
    }

    long long res = 0;
    for(long long x: dp[nxt]) maximize(res, x);
    cout << res << '\n';
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define task "test"
    if (fopen(task".inp", "r")){
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    int t = 1;
//    cin >> t;
    while(t--){
        input();
        solve();
    }
}

Compilation message (stderr)

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