Submission #528026

#TimeUsernameProblemLanguageResultExecution timeMemory
528026hoanghq2004Cloud Computing (CEOI18_clo)C++14
100 / 100
264 ms1296 KiB
#include <bits/stdc++.h>
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;

const int N = 2010 * 50;

int n, m;
long long dp[N];

struct dta {
    int c, f, v, type;
    int operator < (const dta& other) const {
        if (f != other.f) return f > other.f;
        return type > other.type;
    }
};

int main() {
    ios :: sync_with_stdio(0); cin.tie(0);
    vector <dta> events;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int c, f, v;
        cin >> c >> f >> v;
        events.push_back({c, f, v, 1});
    }
    cin >> m;
    for (int i = 0; i < m; ++i) {
        int c, f, v;
        cin >> c >> f >> v;
        events.push_back({c, f, v, -1});
    }
    sort(events.begin(), events.end());
    int cur = 0;
    memset(dp, - 60, sizeof(dp));
    dp[0] = 0;
    for (auto [c, f, v, type]: events) {
        if (type == 1) {
            for (int i = cur; i >= 0; --i)
                dp[i + c] = max(dp[i + c], dp[i] - v);
            cur += c;
        } else {
            for (int i = c; i <= cur; ++i)
                dp[i - c] = max(dp[i - c], dp[i] + v);
        }
    }
    cout << *max_element(dp, dp + N);
}

Compilation message (stderr)

clo.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    2 | #pragma GCC optimization ("O3")
      | 
clo.cpp:3: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    3 | #pragma GCC optimization ("unroll-loops")
      | 
clo.cpp: In function 'int main()':
clo.cpp:45:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   45 |     for (auto [c, f, v, type]: events) {
      |               ^
#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...