Submission #991897

# Submission time Handle Problem Language Result Execution time Memory
991897 2024-06-03T10:45:31 Z crafticat Cloud Computing (CEOI18_clo) C++17
100 / 100
923 ms 2256 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using tup = tuple<ll,ll,ll>;

ll n, q;
ll MAX_SUM = 0;
constexpr ll inf = 1e18;

vector<ll> solve(vector<tup> &data, bool mex) {
    vector<ll> dp(vector<ll>(MAX_SUM + 1,mex ? -inf : inf));
    dp[0] = 0;

    for (ll i = 1; i <= data.size() ; ++i) {
        vector<ll> newDp = dp;
        auto [f,c, v] = data[i - 1];
        for (ll j = 0; j <= MAX_SUM; ++j) {
            if (mex) {
                if (j - c >= 0 && j - c <= MAX_SUM) newDp[j] = max(dp[j],dp[j - c] + v);
            } else {
                if (j - c >= 0 && j - c <= MAX_SUM) newDp[j] = min(dp[j],dp[j - c] + v);
            }
        }
        dp = newDp;
    }

    return dp;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    cin >> n;
    vector<tup> arr;
    ll s1 = 0, s2 = 0;
    for (ll i = 0; i < n; ++i) {
        ll c, f, v; cin >> c >> f >> v;
        arr.emplace_back(f,c,-v);
        s1 += c;
    }

    cin >> q;
    for (ll i = 0; i < q; ++i) {
        ll c, f, v; cin >> c >> f >> v;
        arr.emplace_back(f,-c,v);
        s2 += c;
    }
    MAX_SUM = max(s2, s1);
    std::sort(arr.begin(), arr.end());
    std::reverse(arr.begin(), arr.end());

    auto c = solve(arr, true);

    ll ans = 0;
    for (ll i = 0; i <= MAX_SUM; ++i) {
        ans = max(c[i],ans);
    }

    cout << ans << "\n";
    return 0;
}

Compilation message

clo.cpp: In function 'std::vector<long long int> solve(std::vector<std::tuple<long long int, long long int, long long int> >&, bool)':
clo.cpp:15:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::tuple<long long int, long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |     for (ll i = 1; i <= data.size() ; ++i) {
      |                    ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 213 ms 1248 KB Output is correct
6 Correct 72 ms 604 KB Output is correct
7 Correct 455 ms 1908 KB Output is correct
8 Correct 425 ms 2140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 44 ms 860 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 246 ms 1732 KB Output is correct
8 Correct 40 ms 604 KB Output is correct
9 Correct 400 ms 1884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 464 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 14 ms 580 KB Output is correct
4 Correct 37 ms 604 KB Output is correct
5 Correct 437 ms 1372 KB Output is correct
6 Correct 846 ms 1944 KB Output is correct
7 Correct 844 ms 1944 KB Output is correct
8 Correct 816 ms 1952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 3 ms 348 KB Output is correct
3 Correct 43 ms 916 KB Output is correct
4 Correct 12 ms 348 KB Output is correct
5 Correct 823 ms 1948 KB Output is correct
6 Correct 877 ms 2164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 213 ms 1248 KB Output is correct
6 Correct 72 ms 604 KB Output is correct
7 Correct 455 ms 1908 KB Output is correct
8 Correct 425 ms 2140 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 44 ms 860 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 246 ms 1732 KB Output is correct
16 Correct 40 ms 604 KB Output is correct
17 Correct 400 ms 1884 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 464 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 14 ms 580 KB Output is correct
29 Correct 37 ms 604 KB Output is correct
30 Correct 437 ms 1372 KB Output is correct
31 Correct 846 ms 1944 KB Output is correct
32 Correct 844 ms 1944 KB Output is correct
33 Correct 816 ms 1952 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 3 ms 348 KB Output is correct
36 Correct 43 ms 916 KB Output is correct
37 Correct 12 ms 348 KB Output is correct
38 Correct 823 ms 1948 KB Output is correct
39 Correct 877 ms 2164 KB Output is correct
40 Correct 49 ms 860 KB Output is correct
41 Correct 226 ms 1368 KB Output is correct
42 Correct 10 ms 604 KB Output is correct
43 Correct 913 ms 2256 KB Output is correct
44 Correct 913 ms 2140 KB Output is correct
45 Correct 923 ms 2140 KB Output is correct
46 Correct 5 ms 348 KB Output is correct
47 Correct 10 ms 604 KB Output is correct
48 Correct 9 ms 668 KB Output is correct