제출 #866303

#제출 시각아이디문제언어결과실행 시간메모리
866303vjudge1Cloud Computing (CEOI18_clo)C++17
36 / 100
98 ms262144 KiB
#include <bits/stdc++.h>

#define pb push_back
#define eb emplace_back
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define uniq(x) x.erase(unique(all(x)), x.end())
#define rall(x) x.rbegin(), x.rend()
//#define int long long

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;
const double eps = 1e-9;

void setIO() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

struct T {
    int cores, rate, price;

    bool operator<(T &t) {
        if(rate == t.rate) return price < t.price;
        return rate > t.rate;
    }
};

int32_t main() {
    setIO();

    int n;
    cin >> n;

    vector<T> v;
    v.push_back(T{0, 0, 0});
    ll total = 0;
    for(int i=0; i<n; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        total += a;
        v.push_back(T{a, b, -c});
    }

    int m;
    cin >> m;

    for(int i=0; i<m; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        v.push_back(T{-a, b, c});
    }

    sort(v.begin()+1, v.end());

    // for(T &x : v) {
    //     cout << x.cores << " " << x.rate << " " << x.price << '\n';
    // }

    vector<vector<ll> > dp(n+m+1, vector<ll>(total+1, -1e18));
    dp[0][0] = 0;
    for(int i=1; i<=n+m; i++) {
        for(int j=0; j<=total; j++) {
            dp[i][j] = dp[i-1][j];
            if(j - v[i].cores >= 0 && j - v[i].cores <= total && dp[i-1][j-v[i].cores] != -1e18) {
                dp[i][j] = max(dp[i][j], dp[i-1][j-v[i].cores] + v[i].price);
            }
        }
    }

    ll ans = -1e18;
    for(int i=0; i<=total; i++) ans = max(ans, dp[n+m][i]);
    cout << ans << '\n';
    return 0;
}
#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...