제출 #787145

#제출 시각아이디문제언어결과실행 시간메모리
787145c2zi6Cloud Computing (CEOI18_clo)C++14
100 / 100
948 ms3712 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; struct NODE { ll w; ll f; ll v; bool operator<(const NODE& b) { if (this->f == b.f) return this->w > b.w; return this->f > b.f; } }; const ll MAXW = 4000 * 50 + 100; void solve() { ll N, M; vector<NODE> a; cin >> N; for (int i = 0; i < N; i++) { ll c, f, v; cin >> c >> f >> v; a.push_back({c, f, -v}); } cin >> M; for (int i = 0; i < M; i++) { ll c, f, v; cin >> c >> f >> v; a.push_back({-c, f, v}); } sort(a.begin(), a.end()); //for (auto x : a) cout << x.w << " " << x.v << endl; ll n = a.size(); ll dp[2][MAXW]; for (int i = 0; i < MAXW; i++) dp[0][i] = -1e18; dp[0][0] = 0; for (int i = 1; i <= n; i++) { ll v = a[i-1].v; ll w = a[i-1].w; int cur = i%2; int prev = !cur; for (int j = MAXW-1; j >= 0; j--) { dp[cur][j] = dp[prev][j]; if (j - w >= 0 && j - w < MAXW && dp[prev][j - w] != -1e18) dp[cur][j] = max(dp[cur][j], dp[prev][j - w] + v); } } ll ans = 0; for (int i = 0; i < MAXW; i++) ans = max(ans, dp[n%2][i]);//cout << x << " "; cout << endl; cout << ans << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; //cin >> t; while (t--) 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...