Submission #1268293

#TimeUsernameProblemLanguageResultExecution timeMemory
1268293tnknguyen_Cloud Computing (CEOI18_clo)C++20
100 / 100
404 ms2192 KiB
#include <bits/stdc++.h> using namespace std; #define endl '\n' #define ll long long #define len(s) (int)s.size() #define int long long #define pii pair<int, int> #define fi first #define se second #define MASK(k) (1LL << (k)) struct st{ int c, f, p; }; int n, m, C = 0; vector<st> v; int f[2][100005]; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); //freopen("DATPHONG.inp","r",stdin); //freopen("DATPHONG.out","w",stdout); cin >> n; for(int i=1; i<=n; ++i){ int c, f, p; cin >> c >> f >> p; v.push_back({c, f, -p}); C += c; } cin >> m; for(int i=1; i<=m; ++i){ int c, f, p; cin >> c >> f >> p; v.push_back({-c, f, p}); } sort(v.begin(), v.end(), [](st &X, st &Y){ if(X.f == Y.f) return (X.c > Y.c); return (X.f > Y.f); }); memset(f, -63, sizeof f); int INF = f[0][0]; f[0][0] = f[1][0] = 0; int op = 0; for(int i=0; i<len(v); ++i){ op ^= 1; for(int j=0; j<=C; ++j){ int pre = j - v[i].c; f[op][j] = f[op^1][j]; if(0 <= pre && pre <= C && f[op^1][pre] != INF) f[op][j] = max(f[op][j], f[op^1][pre] + v[i].p); } } int ans = 0; for(int j=0; j<=C; ++j) ans = max(ans, f[op][j]); cout << ans; 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...