제출 #982817

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define MASK(i) (1LL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
#define ALL(v) (v).begin(), (v).end()

ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}

ll LASTBIT(ll mask){return (mask) & (-mask);}
int pop_cnt(ll mask){return __builtin_popcountll(mask);}
int ctz(ll mask){return __builtin_ctzll(mask);}
int logOf(ll mask){return __lg(mask);}

mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);}

template <class T1, class T2>
    bool maximize(T1 &a, T2 b){
        if (a < b) {a = b; return true;}
        return false;
    }

template <class T1, class T2>
    bool minimize(T1 &a, T2 b){
        if (a > b) {a = b; return true;}
        return false;
    }

template <class T>
    void printArr(T& container, char separator = ' ', char finish = '\n'){
        for(auto item: container) cout << item << separator;
        cout << finish;
    }
    
#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")

template <class T>
    void remove_dup(vector<T> &a){
        sort(ALL(a));
        a.resize(unique(ALL(a)) - a.begin());
    }

struct Stuff{
    long c, f, v;
    Stuff(long _c, long _f, long _v) {c=  _c, f = _f, v = _v;}

    bool operator < (Stuff x) const{
        return f < x.f;
    }
};

const long N = 2009;
const ll INF = 1e18;
ll dp[N][51];
ll sweep[51], tmp[51];

int main(void){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    long n; cin >> n;
    vector<Stuff> computers;
    for(long i = 0; i<n; ++i){
        long c, f, v; cin >> c >> f >> v;
        computers.push_back(Stuff(c, f, v));
    }
    long m; cin >> m;
    vector<Stuff> orders;
    for(long i= 0; i<m; ++i){
        long c, f, v; cin >> c >> f >> v;
        orders.push_back(Stuff(c, f, v));
    }
    sort(ALL(computers)); sort(ALL(orders));

    for(long i = 0; i<=n; ++i)
    for(long j = 1; j<=50; ++j) dp[i][j] = -INF;

    long start = 0;
    for(Stuff item: orders){
        while(start < n && computers[start].f < item.f) start++;
        for(long i = 1; i < n; ++i)
        for(long j = 0; j<=50; ++j) maximize(dp[i][0], dp[i-1][j]);

        for(long i = 1; i<=item.c; ++i) sweep[i] = -INF;
        sweep[0] = 0;
        for(long i = start; i < n; ++i){
            for(long j= 0; j<=item.c; ++j) tmp[j] = sweep[j];
            for(long j = item.c - computers[i].c; j>=0; --j){
                maximize(sweep[j + computers[i].c], sweep[j] - computers[i].v);
            }
            for(long j = 0; j<computers[i].c; ++j){
                long t = computers[i].c - j;
                ll cost = dp[i][j];
                if (j == 0) cost -= computers[i].v;
                if (t <= item.c) maximize(sweep[t], cost);
            }

            for(long j = computers[i].c - item.c; j >= 0; --j){
                ll cost = dp[i][j] + item.v;
                if (j == 0) cost -= computers[i].v;
                maximize(dp[i][j + item.c], cost);
            }
            for(long j = 0; j<=computers[i].c; ++j){
                long t = item.c - j;
                if (t < 0) break;
                if (tmp[t] == -INF) continue;
                ll cost = tmp[t];
                if (j > 0) cost -= computers[i].v;
                maximize(dp[i][j], cost + item.v);
            }

//            for(long j = 0; j<=computers[i].c; ++j) cout << dp[i][j] << " ";
//            cout << "\n";

        }
    }

    ll ans = -INF;
    for(long i = 0; i<=n; ++i)
    for(long j = 0; j<=50; ++j) maximize(ans, dp[i][j]);

    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...