Submission #1022380

#TimeUsernameProblemLanguageResultExecution timeMemory
1022380NValchanovCloud Computing (CEOI18_clo)C++17
100 / 100
295 ms1624 KiB
#include <bits/stdc++.h> #define endl '\n' using namespace std; typedef long long ll; const int MAXN = 2e3 + 10; const int MAXC = 50 + 10; const int SUMC = MAXN * MAXC; const int MAXF = 1e9 + 10; const int MAXV = 1e9 + 10; const ll INF = 4e18 + 10; struct item { int rate; int cores; int cost; bool type; item() { rate = 0; cores = 0; cost = 0; type = 0; } item(int _cores, int _rate, int _cost, bool _type) { cores = _cores; rate = _rate; cost = _cost; type = _type; } friend bool operator<(item it1, item it2) { if(it1.rate == it2.rate) return it1.type < it2.type; return it1.rate > it2.rate; } }; int n, m; vector < item > items; ll dp[SUMC]; ll sum_cores; void read() { cin >> n; for(int i = 1; i <= n; i++) { int cores, rate, cost; cin >> cores >> rate >> cost; sum_cores += cores; items.push_back(item(cores, rate, cost, 0)); } cin >> m; for(int i = 1; i <= m; i++) { int cores, rate, cost; cin >> cores >> rate >> cost; items.push_back(item(cores, rate, cost, 1)); } } void solve() { sort(items.begin(), items.end()); for(int i = 1; i <= sum_cores; i++) { dp[i] = -INF; } dp[0] = 0; for(item it : items) { if(it.type == 0) { for(int i = sum_cores; i - it.cores >= 0; i--) { dp[i] = max(dp[i], dp[i - it.cores] - it.cost); } } else { for(int i = 0; i + it.cores <= sum_cores; i++) { dp[i] = max(dp[i], dp[i + it.cores] + it.cost); } } } ll ans = -INF; for(int i = 0; i <= sum_cores; i++) { ans = max(ans, dp[i]); } cout << ans << endl; } int main() { ios_base :: sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); read(); solve(); 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...