Submission #1336787

#TimeUsernameProblemLanguageResultExecution timeMemory
1336787hauserlCloud Computing (CEOI18_clo)C++20
18 / 100
235 ms1200 KiB
#include <bits/stdc++.h>
#define ll long long
using namespace std;

struct C{
    int c;
    int f;
    int v;
    int t; // 1 for offer, -1 for order
    bool operator<(const auto& o) const {
        if (f != o.f) return f > o.f;
        return t > o.t;
    }
};

int main() {
    vector<C> computers;
    int n; scanf("%d",&n);
    for (int i = 0; i < n; i++) {
        int c,f,v; scanf("%d %d %d",&c,&f,&v);
        computers.push_back(C{c,f,v, 1});
    }

    int m; scanf("%d",&m);
    for (int i = 0; i < m; i++) {
        int c,f,v; scanf("%d %d %d",&c,&f,&v);
        computers.push_back(C{c,f,v,-1});
    }

    sort(computers.begin(), computers.end());

    int maxCores = 1e5+5;
    vector<ll> dp(maxCores+1, INT_MIN);
    dp[0] = 0;

    for (const auto& computer : computers) {
        if (computer.t == 1) {
            for (int j = maxCores; j >= computer.c; j--) {
                dp[j] = max(dp[j], dp[j-computer.c] - computer.v);
            }
        } else {
            for (int j = 0; j <= maxCores-computer.c; j++) {
                dp[j] = max(dp[j], dp[j+computer.c]+computer.v);
            }
        }
    }

    ll ma = 0;
    for (int i = 0; i < maxCores+1; i++) {
        ma = max(ma, dp[i]);
    }

    printf("%lld", ma);
    return 0;
}

Compilation message (stderr)

clo.cpp: In function 'int main()':
clo.cpp:18:17: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |     int n; scanf("%d",&n);
      |            ~~~~~^~~~~~~~~
clo.cpp:20:25: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         int c,f,v; scanf("%d %d %d",&c,&f,&v);
      |                    ~~~~~^~~~~~~~~~~~~~~~~~~~~
clo.cpp:24:17: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |     int m; scanf("%d",&m);
      |            ~~~~~^~~~~~~~~
clo.cpp:26:25: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         int c,f,v; scanf("%d %d %d",&c,&f,&v);
      |                    ~~~~~^~~~~~~~~~~~~~~~~~~~~
#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...