Submission #205700

#TimeUsernameProblemLanguageResultExecution timeMemory
205700dolphingarlicCloud Computing (CEOI18_clo)C++14
54 / 100
830 ms2168 KiB
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#define FOR(i, x, y) for (int i = x; i < y; i++)
typedef long long ll;
using namespace std;

const ll INF = LLONG_MIN / 2;

struct Object {
    int c;
    ll f, v;
    bool operator<(Object B) {
        if (f == B.f) {
            if (v == B.v) return c > B.c;
            return v > B.v;
        }
        return f > B.f;
    }
} obj[4001];

ll dp[2][100001];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n;
    FOR(i, 0, n) {
        cin >> obj[i].c >> obj[i].f >> obj[i].v;
        obj[i].v *= -1;
    }
    cin >> m;
    FOR(i, n, n + m) {
        cin >> obj[i].c >> obj[i].f >> obj[i].v;
        obj[i].c *= -1;
    }
    sort(obj, obj + n + m);

    FOR(i, 0, 2) FOR(j, 0, 100001) dp[i][j] = INF;
    dp[1][0] = 0;
    FOR(i, 0, n + m) {
        FOR(j, 0, 99951) {
            if (j >= obj[i].c)
                dp[i & 1][j] = max(dp[1 - i & 1][j], dp[1 - i & 1][j - obj[i].c] + obj[i].v);
            else
                dp[i & 1][j] = dp[1 - i & 1][j];
        }
        FOR(j, 0, 100001) dp[1 - i & 1][j] = INF;
    }

    cout << *max_element(dp[1 - (n + m) & 1], dp[1 - (n + m) & 1] + 100001);
    return 0;
}

Compilation message (stderr)

clo.cpp: In function 'int main()':
clo.cpp:44:41: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
                 dp[i & 1][j] = max(dp[1 - i & 1][j], dp[1 - i & 1][j - obj[i].c] + obj[i].v);
                                       ~~^~~
clo.cpp:44:59: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
                 dp[i & 1][j] = max(dp[1 - i & 1][j], dp[1 - i & 1][j - obj[i].c] + obj[i].v);
                                                         ~~^~~
clo.cpp:46:37: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
                 dp[i & 1][j] = dp[1 - i & 1][j];
                                   ~~^~~
clo.cpp:48:32: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
         FOR(j, 0, 100001) dp[1 - i & 1][j] = INF;
                              ~~^~~
clo.cpp:51:31: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
     cout << *max_element(dp[1 - (n + m) & 1], dp[1 - (n + m) & 1] + 100001);
                             ~~^~~~~~~~~
clo.cpp:51:52: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
     cout << *max_element(dp[1 - (n + m) & 1], dp[1 - (n + m) & 1] + 100001);
                                                  ~~^~~~~~~~~
#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...