Submission #77964

#TimeUsernameProblemLanguageResultExecution timeMemory
77964aminraCloud Computing (CEOI18_clo)C++14
0 / 100
677 ms7220 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; const int MOD = (int)1e9 + 7; const int MAXN = (int)2e5 + 7; const int MAXS = (int)100006; const int infint = (int)1e9; const ll inf = (ll)1e18; ll n, dp[MAXS], tmp[MAXS], sz; struct machine{ ll c, f, v; } m[MAXN]; struct person{ ll C, F, V; } p[MAXN]; vector<ll> which[MAXN]; bool cmp(person a, person b) { return a.F < b.F; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for (int i = 0; i < n; i++) cin >> m[i].c >> m[i].f >> m[i].v; cin >> sz; for (int i = 0; i < sz; i++) cin >> p[i].C >> p[i].F >> p[i].V; sort(p, p + sz, cmp); vector<ll> v; for (int i = 0; i < sz; i++) v.push_back(p[i].F); for (int i = 0; i < n; i++) { int idx = upper_bound(v.begin(), v.end(), m[i].f) - v.begin() - 1; if(idx != -1) which[idx].push_back(i); } for (int i = 0; i < MAXS; i++) dp[i] = -inf; dp[0] = 0; for (int i = sz - 1; i >= 0; i--) { for (auto u : which[i]) { for (int j = 0; j < MAXS; j++) tmp[i] = -inf; for (int j = 0; j < MAXS; j++) { tmp[j] = dp[j]; if(j >= m[u].c) tmp[j] = max(tmp[j], dp[j - m[u].c] - m[u].v); } for (int j = 0; j < MAXS; j++) dp[j] = tmp[j]; } for (int j = 0; j < MAXS; j++) { if(j + p[i].F < MAXS) dp[j] = max(dp[j], dp[j + p[i].C] + p[i].V); } } ll mx = 0; for (int i = 0; i < MAXS; i++) mx = max(mx, dp[i]); cout << mx; }
#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...