Submission #1291488

#TimeUsernameProblemLanguageResultExecution timeMemory
1291488thaibeo123Cloud Computing (CEOI18_clo)C++20
100 / 100
171 ms1296 KiB
#include <bits/stdc++.h>
using namespace std;

#define NAME "A"
#define ll long long
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define MASK(x) (1ll << (x))
#define BIT(x, i) (((x) >> (i)) & 1)

const int N = 1e5 + 5;
const ll inf = 1e18;

struct Node {
    int c, f, v;
};

bool cmp(Node &a, Node &b) {
    return a.f > b.f;
}

int n, m;
int pre[N];
ll dp[N];
Node a[N], b[N];

void input() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i].c >> a[i].f >> a[i].v;
    }
    cin >> m;
    for (int i = 1; i <= m; i++) {
        cin >> b[i].c >> b[i].f >> b[i].v;
    }
    sort(a + 1, a + 1 + n, cmp);
    sort(b + 1, b + 1 + m, cmp);
    for (int i = 1; i <= n; i++) {
        pre[i] = pre[i - 1] + a[i].c;
    }
}

void solve() {
    dp[0] = 0;
    for (int i = 1; i <= pre[n]; i++) {
        dp[i] = -inf;
    }
    int j = 1;
    for (int i = 1; i <= m; i++) {
        while (j <= n && a[j].f >= b[i].f) {
            for (int t = pre[j]; t >= a[j].c; t--) {
                dp[t] = max(dp[t], dp[t - a[j].c] - a[j].v);
            }
            j++;
        }
        for (int t = 0; t <= pre[j - 1] - b[i].c; t++) {
            dp[t] = max(dp[t], dp[t + b[i].c] + b[i].v);
        }
    }
    ll ans = 0;
    for (int i = 0; i <= pre[n]; i++) {
        ans = max(ans, dp[i]);
    }
    cout << ans;
}

signed main() {
    if (fopen(NAME".INP", "r")) {
        freopen(NAME".INP", "r", stdin);
        freopen(NAME".OUT", "w", stdout);
    }
    cin.tie(0)->sync_with_stdio(0);

    int t = 1;
    //cin >> t;
    while (t--) {
        input();
        solve();
    }

    return 0;
}

Compilation message (stderr)

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