Submission #1253280

#TimeUsernameProblemLanguageResultExecution timeMemory
1253280orzminhhcCloud Computing (CEOI18_clo)C++20
54 / 100
14 ms584 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned int ul;
typedef unsigned long long ull;

#define Mask(i) (1ULL << (i))
#define getbit(mask, i) (((mask) >> (i)) & 1)
#define all(v) (v).begin(), (v).end()
#define IN "A.INP"
#define OUT "A.OUT"
#define int long long

ll gcd(ll a, ll b){return __gcd(a, b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}

ll lastbit(ll mask){return (mask) & (-mask);}
int pop_cnt(ll mask){return __builtin_popcountll(mask);}
int ctz(ull mask){return __builtin_ctzll(mask);}

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 the_array_itself, string separator = " ", string finish = "\n", ostream &out = cout){
        for(auto item: the_array_itself) out << item << separator;
        out << finish;
    }

template <class T>
    void remove_dup(vector<T> &a){
        sort(all(a));
        a.resize(unique(all(a)) - a.begin());
    }
// End of the template, let's drink a cup of water before reading:D
// Template use for ONLINE JUDGE

const int inf = 1e18, mod = 1e9+7;
const int maxcore = 5005;

struct List{
    int c,f,v,type;
};

bool cmp(const List &x, const List &y){
    if(x.f != y.f) return x.f > y.f;
    return x.type < y.type;
}

void solve(){

   int n; cin >> n;
   vector<List> a;
   for(int i = 0; i < n; i ++){
        int c,f,v; cin >> c >> f >> v;
        a.push_back({c,f,v,0});
   }

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

   sort(all(a), cmp);


   vector<int> dp(maxcore + 1, -inf);
   dp[0] = 0;
   for(List item : a){
        int c = item.c, f = item.f, v = item.v;
        if(item.type == 0){
            for(int i = maxcore; i >= c; i--) if(dp[i-c] != -inf) maximize(dp[i], dp[i-c] - v);
        }
        else {
            for(int i = 0; i <= maxcore - c; i ++) if(dp[i+c] != -inf) maximize(dp[i], dp[i+c] + v);
        }
   }

   cout << *max_element(all(dp));
}

signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int t = 1; // cin >> t;
    while(t--) solve();
    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...