Submission #1105714

# Submission time Handle Problem Language Result Execution time Memory
1105714 2024-10-27T12:07:28 Z xydwe12312 Cloud Computing (CEOI18_clo) C++14
100 / 100
1373 ms 6224 KB
#include <bits/stdc++.h>
using namespace std;

// Macros
#define pb          push_back
#define pf          push_front
#define ff          first
#define ss          second
#define all(v)      v.begin(), v.end()
#define rall(v)     v.rbegin(), v.rend()
#define up(v)       upper_bound(v)
#define low(v)      lower_bound(v)

// Read and Print
#define read(a, n) for(ll i = 0; i < n; ++i) cin >> a[i];
#define print(a, n) for(ll i = 0; i < n; ++i){ cout << a[i] << " ";} cout << "\n";
#define endl "\n"
#define sp " "

// Typedefs
typedef long long ll;
typedef long double ld;
typedef long long int lli;
typedef pair<ll, ll> pll;
typedef pair<lli, lli> plli;
typedef pair<int, int> pii;
typedef vector<ll> vi;
typedef vector<vector<lli>> vvi;
using vec = vector<int>;

// Constants
const ll mxn = 1e6 + 5;
const ll mod = 1e9 + 7;

// Solve
const ll N = 1e5 + 5;
const ll INF = 1e18 + 6;

void solve() {

    ll n, m, sum = 0;
    vector <vector<ll>> a;

    cin >> n;
    for (ll i = 1; i <= n; i++) {
        ll c, f, p;
        cin >> c >> f >> p;
        a.pb({c, f, -p});
        sum += c;
    }
    cin >> m;
    for (ll j = 0; j < m; j++) {
        ll c, f, p;
        cin >> c >> f >> p;
        a.pb({ -c, f, p});
    }

    vector<vi> dp(sum + 1, vi(2, 0));
    for (int i = 1; i <= sum; i++) dp[i][0] = -INF;

    auto comp = [&](vector<ll> &a, vector<ll> &b) ->bool{
        return a[1] != b[1] ? a[1] > b[1] : a[2] < b[2];
    };

    sort(all(a), comp);


    for (ll i = 0; i < a.size(); i++) {
        for (ll j = 0; j <= sum; j++)
            dp[j][1] = dp[j][0];
        for (ll j = 0; j <= sum; j++) {
            ll pre = j - a[i][0];
            if (pre >= 0 && pre <= sum && dp[pre][0] != -INF)
                dp[j][1] = max(dp[j][1], dp[pre][0] + a[i][2]);
        }
        for (ll j = 0; j <= sum; j++)
            dp[j][0] = dp[j][1];
    }
    ll ans = -INF;
    for (ll i = 0; i <= sum; i++)
        ans = max(ans, dp[i][0]);
    cout << ans << endl;



}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

Compilation message

clo.cpp: In function 'void solve()':
clo.cpp:68:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |     for (ll i = 0; i < a.size(); i++) {
      |                    ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 3 ms 592 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
7 Correct 6 ms 760 KB Output is correct
8 Correct 6 ms 668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 72 ms 1784 KB Output is correct
6 Correct 4 ms 336 KB Output is correct
7 Correct 301 ms 3292 KB Output is correct
8 Correct 52 ms 1104 KB Output is correct
9 Correct 557 ms 5200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 464 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 2 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 18 ms 808 KB Output is correct
4 Correct 3 ms 592 KB Output is correct
5 Correct 583 ms 3408 KB Output is correct
6 Correct 1342 ms 5456 KB Output is correct
7 Correct 1228 ms 5456 KB Output is correct
8 Correct 1266 ms 5456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 3 ms 616 KB Output is correct
3 Correct 67 ms 1872 KB Output is correct
4 Correct 12 ms 468 KB Output is correct
5 Correct 1261 ms 5456 KB Output is correct
6 Correct 1075 ms 5456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 3 ms 592 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
7 Correct 6 ms 760 KB Output is correct
8 Correct 6 ms 668 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 72 ms 1784 KB Output is correct
14 Correct 4 ms 336 KB Output is correct
15 Correct 301 ms 3292 KB Output is correct
16 Correct 52 ms 1104 KB Output is correct
17 Correct 557 ms 5200 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 464 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 2 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 18 ms 808 KB Output is correct
29 Correct 3 ms 592 KB Output is correct
30 Correct 583 ms 3408 KB Output is correct
31 Correct 1342 ms 5456 KB Output is correct
32 Correct 1228 ms 5456 KB Output is correct
33 Correct 1266 ms 5456 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 3 ms 616 KB Output is correct
36 Correct 67 ms 1872 KB Output is correct
37 Correct 12 ms 468 KB Output is correct
38 Correct 1261 ms 5456 KB Output is correct
39 Correct 1075 ms 5456 KB Output is correct
40 Correct 81 ms 1616 KB Output is correct
41 Correct 225 ms 2384 KB Output is correct
42 Correct 13 ms 592 KB Output is correct
43 Correct 1373 ms 5968 KB Output is correct
44 Correct 1311 ms 5968 KB Output is correct
45 Correct 1127 ms 6224 KB Output is correct
46 Correct 7 ms 592 KB Output is correct
47 Correct 15 ms 592 KB Output is correct
48 Correct 13 ms 756 KB Output is correct