Submission #1110697

#TimeUsernameProblemLanguageResultExecution timeMemory
1110697IcelastCloud Computing (CEOI18_clo)C++17
100 / 100
628 ms2384 KiB
#include <iostream> #include <bits/stdc++.h> #define ll long long using namespace std; const ll maxn = 2*1e5+5, INF = 4e18+9; struct computer{ ll c, f, v; }; struct obj{ ll c, f, v; }; void solve(){ int n; cin >> n; vector<obj> a; for(int i = 1; i <= n; i++){ ll c, f, v; cin >> c >> f >> v; a.push_back({c, f, -v}); } int m; cin >> m; for(int i = 1; i <= m; i++){ ll c, f, v; cin >> c >> f >> v; a.push_back({-c, f, v}); } sort(a.begin(), a.end(), [](obj a, obj b){return a.f > b.f || (a.f == b.f && a.c > b.c);}); auto chmax = [&](ll &a, ll b) -> void{ a = max(a, b); }; int N = 2000*50; vector<ll> f(N+1, -INF), prv(N+1, -INF); f[0] = 0; for(obj it : a){ prv = f; fill(f.begin(), f.end(), INF); for(int j = 0; j <= N; j++){ f[j] = prv[j]; if(j-it.c >= 0 && j-it.c <= N) chmax(f[j], prv[j-it.c]+it.v); } } ll ans = 0; for(int j = 0; j <= N; j++){ chmax(ans, f[j]); } cout << ans; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); }
#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...