제출 #1091752

#제출 시각아이디문제언어결과실행 시간메모리
1091752gygCloud Computing (CEOI18_clo)C++17
36 / 100
665 ms7000 KiB
#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define arr array
const int MX_N = 2e3 + 5, MX_M = 2e3 + 5, MX_C = 2e5 + 5, INF = 1e18;

int n, m;
struct Evnt {
    bool is_gn;
    int cp, pwr, vl;
    bool operator<(Evnt othr) {
        if (othr.pwr == pwr) return is_gn;
        return pwr > othr.pwr;
    }
};
arr<Evnt, MX_N + MX_M> evnt;

arr<arr<int, MX_C>, 2> dp;
void cmp() {
    for (int c = 1; c <= 1e5; c++) dp[0][c] = -INF;
    
    for (int i = 1; i <= n + m; i++) {
        int prty = i % 2, opp_prty = (i + 1) % 2;
        if (evnt[i].is_gn) {
            for (int c = 0; c <= 1e5; c++) {
                if (c - evnt[i].cp >= 0) dp[prty][c] = max(dp[opp_prty][c], dp[opp_prty][c - evnt[i].cp] - evnt[i].vl);
                else dp[prty][c] = dp[opp_prty][c];
            }    
        } else {
            for (int c = 0; c <= 1e5; c++) {
                if (c + evnt[i].cp <= 1e5) dp[prty][c] = max(dp[opp_prty][c], dp[opp_prty][c + evnt[i].cp] + evnt[i].vl);
                else dp[prty][c] = dp[opp_prty][c];
            }
        }
    }
}

signed main() {
    // freopen("cld.in", "r", stdin);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        int cp, pwr, vl; cin >> cp >> pwr >> vl;
        evnt[i] = {true, cp, pwr, vl};
    }
    cin >> m;
    for (int i = 1; i <= m; i++) {
        int cp, pwr, vl; cin >> cp >> pwr >> vl;
        evnt[n + i] = {false, cp, pwr, vl};
    }
    sort(evnt.begin() + 1, evnt.begin() + n + m + 1);

    cmp();
    int ans = 0;
    for (int c = 0; c <= 1e5; c++) ans = max(ans, dp[(n + m) % 2][c]);
    cout << ans << endl;
}
#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...