Submission #1058996

#TimeUsernameProblemLanguageResultExecution timeMemory
1058996manhlinh1501Cloud Computing (CEOI18_clo)C++17
0 / 100
1 ms4984 KiB
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
const i64 oo64 = 1e15;
const int MAXN = 2e5 + 5;

struct node {
    int x, y, z, p;
    node(int x = 0, int y = 0, int z = 0, int p = 0) : x(x), y(y), z(z), p(p) {}
};

int N, M;
node a[MAXN];
i64 dp[MAXN];
int tot = 0;

signed main() {
#define TASK "code"

    if (fopen(TASK ".inp", "r")) {
        freopen(TASK ".inp", "r", stdin);
        freopen(TASK ".out", "w", stdout);
    }

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> N;
    for(int i = 1; i <= N; i++) {
        auto &[x, y, z, p] = a[i];
        cin >> x >> y >> z;
        tot += x;
        p = -1;
    }
    cin >> M;
    for(int i = N + 1; i <= N + M; i++) {
        auto &[x, y, z, p] = a[i];
        cin >> x >> y >> z;
        p = i;
    }
    sort(a + 1, a + N + M + 1, [&](const node a, const node b) {
        if(a.y != b.y) return a.y > b.y;
        return a.p < b.p;
    });
    for(int i = 1; i <= tot; i++) dp[i] = -oo64;
    dp[0] = 0;
    for(int i = 1; i <= N + M; i++) {
        const auto [x, y, z, p] = a[i];
        if(p == -1) {
            for(int j = tot; j >= x; j--)
                dp[j] = max(dp[j], dp[j - x] - z);
        } else {
            for(int j = 0; j <= tot - x; j++)
                dp[j] = max(dp[j], dp[j + x] + z);
        }
    }
    cout << *max_element(dp + 1, dp + tot + 1);
    return (0 ^ 0);
}

Compilation message (stderr)

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