Submission #1267027

#TimeUsernameProblemLanguageResultExecution timeMemory
1267027menkhCloud Computing (CEOI18_clo)C++20
72 / 100
423 ms2192 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++) #define FORD(i, b, a) for (int i = (b), _a = (a); i >= _a; i--) #define REP(i, n) for (int i = 0, _n = (n); i < _n; i++) #define INF 1000000000000 struct item { int need, fac, earn; }; int n, m; vector<item> hihi; void solve() { cin >> n; for (int i = 0; i < n; i++) { int c, f, p; cin >> c >> f >> p; hihi.push_back({c, f, -p}); } cin >> m; for (int i = 0; i < m; i++) { int c, f, p; cin >> c >> f >> p; hihi.push_back({-c, f, p}); } sort(hihi.begin(), hihi.end(), [](item A, item B) { // if (A.fac == B.fac) return A.need > B.need; return A.fac > B.fac; }); int maxRoom = 2000 * 50 + 1; vector<int> dp(maxRoom + 5, -INF); dp[0] = 0; for (item cur : hihi) { vector<int> nxt = dp; for (int j = 0; j < maxRoom; j++) { int pre = j - cur.need; if (pre < 0 || pre > maxRoom || dp[pre] == -INF) continue; int nw = dp[pre] + cur.earn; nxt[j] = max(nxt[j], nw); } swap(dp, nxt); } cout << *max_element(dp.begin(), dp.end()) << '\n'; } signed main() { // freopen("DATPHONG.INP", "r", stdin); // freopen("DATPHONG.OUT", "w", stdout); ios_base::sync_with_stdio(false); cin.tie(0); 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...