제출 #703908

#제출 시각아이디문제언어결과실행 시간메모리
703908finn__Cloud Computing (CEOI18_clo)C++17
72 / 100
631 ms2124 KiB
#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize("O3")
#pragma GCC target("avx2")

struct Transaction
{
    uint64_t f;
    int64_t c, v;

    bool operator<(Transaction const &t) const { return f > t.f; }
};

#define N 4000
#define C 51

Transaction t[N];
int64_t dp[N * C];

int main()
{
    size_t n, l = 0;
    cin >> n;

    for (size_t i = 0; i < n; i++)
    {
        cin >> t[l].c >> t[l].f >> t[l].v;
        t[l].v = -t[l].v;
        l++;
    }

    size_t m;
    cin >> m;

    for (size_t i = 0; i < m; i++)
    {
        cin >> t[l].c >> t[l].f >> t[l].v;
        t[l].c = -t[l].c;
        l++;
    }

    sort(t, t + l);
    fill(dp + 1, dp + N * C, INT64_MIN);

    for (auto const &[f, c, v] : t)
    {
        if (c < 0)
        {
            for (int64_t i = -c; i < N * C; i++)
                if (dp[i] != INT64_MIN)
                    dp[i + c] = max(dp[i + c], dp[i] + v);
        }
        else
        {
            for (int64_t i = N * C - c - 1; i >= 0; i--)
                if (dp[i] != INT64_MIN)
                    dp[i + c] = max(dp[i + c], dp[i] + v);
        }
    }

    int64_t max_value = 0;
    for (size_t i = 0; i < N * C; i++)
        max_value = max(max_value, dp[i]);

    cout << max_value << '\n';
}
#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...