Submission #866304

#TimeUsernameProblemLanguageResultExecution timeMemory
866304vjudge1Cloud Computing (CEOI18_clo)C++17
100 / 100
613 ms2908 KiB
#include <bits/stdc++.h> #define pb push_back #define eb emplace_back #define sz(x) (int)x.size() #define all(x) x.begin(), x.end() #define uniq(x) x.erase(unique(all(x)), x.end()) #define rall(x) x.rbegin(), x.rend() //#define int long long using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; const int mod = 1e9 + 7; const int LOG = 20; const int maxn = 1e5 + 5; const double eps = 1e-9; void setIO() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); } struct T { int cores, rate, price; bool operator<(T &t) { if(rate == t.rate) return price < t.price; return rate > t.rate; } }; int32_t main() { setIO(); int n; cin >> n; vector<T> v; v.push_back(T{0, 0, 0}); ll total = 0; for(int i=0; i<n; i++) { int a, b, c; cin >> a >> b >> c; total += a; v.push_back(T{a, b, -c}); } int m; cin >> m; for(int i=0; i<m; i++) { int a, b, c; cin >> a >> b >> c; v.push_back(T{-a, b, c}); } sort(v.begin()+1, v.end()); // for(T &x : v) { // cout << x.cores << " " << x.rate << " " << x.price << '\n'; // } vector<vector<ll> > dp(2, vector<ll>(total+1, -1e18)); dp[0][0] = 0; for(int i=1; i<=n+m; i++) { for(int j=0; j<=total; j++) { dp[1][j] = dp[0][j]; if(j - v[i].cores >= 0 && j - v[i].cores <= total && dp[0][j-v[i].cores] != -1e18) { dp[1][j] = max(dp[0][j], dp[0][j-v[i].cores] + v[i].price); } } swap(dp[0], dp[1]); } ll ans = -1e18; for(int i=0; i<=total; i++) ans = max(ans, dp[0][i]); cout << ans << '\n'; 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...