Submission #827341

#TimeUsernameProblemLanguageResultExecution timeMemory
827341PanosPaskCloud Computing (CEOI18_clo)C++14
36 / 100
88 ms262144 KiB
#include <bits/stdc++.h>
#define pb push_back

using namespace std;

typedef long long ll;

const ll INF = 1e18;

struct Event {
    int profit_change;
    int core_change;
    int rate;

    bool operator < (Event b) {
        if (this->rate == b.rate)
            return this->core_change < b.core_change;

        return this->rate > b.rate;
    }
};

int N, M;

// dp[i][j]: After the first i events (sorted in clock rate), maximum profit with at least j cores left over
vector<vector<ll>> dp;
vector<Event> events;

int main(void)
{
    scanf("%d", &N);


    for (int i = 0; i < N; i++) {
        int c, f, v;
        scanf("%d %d %d", &c, &f, &v);

        events.pb({-v, c, f});
    }

    scanf("%d", &M);
    for (int i = 0; i < M; i++) {
        int c, f, v;
        scanf("%d %d %d", &c, &f, &v);

        events.pb({v, -c, f});
    }

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

    dp.resize(N + M + 1, vector<ll>(N * 50 + 1));
    dp[0].assign(N * 50 + 1, -INF);
    dp[0][0] = 0;

    for (int i = 1; i <= N + M; i++) {
        int cores = events[i - 1].core_change;
        int v = events[i - 1].profit_change;
        for (int j = 0; j <= N * 50; j++) {
            dp[i][j] = dp[i - 1][j];
            if (j - cores >= 0 && j - cores <= N * 50 && dp[i - 1][j - cores] != -INF)
                dp[i][j] = max(dp[i][j], dp[i - 1][j - cores] + v);
        }
    }

    ll ans = 0;
    for (int i = 0; i < N * 50; i++)
        ans = max(ans, dp[N + M][i]);

    printf("%lld\n", ans);
}

Compilation message (stderr)

clo.cpp: In function 'int main()':
clo.cpp:31:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |     scanf("%d", &N);
      |     ~~~~~^~~~~~~~~~
clo.cpp:36:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |         scanf("%d %d %d", &c, &f, &v);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:41:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |     scanf("%d", &M);
      |     ~~~~~^~~~~~~~~~
clo.cpp:44:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |         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...