제출 #897232

#제출 시각아이디문제언어결과실행 시간메모리
897232vaneaCloud Computing (CEOI18_clo)C++14
100 / 100
407 ms1364 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int mxN = 1e5+1; const ll NINF = -1e18; ll dp[mxN+10]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<array<int, 3>> v; for(int i = 0; i < n; i++) { int cores, freq, price; cin >> cores >> freq >> price; v.push_back({cores, freq, price}); } int m; cin >> m; while(m--) { int cores, freq, price; cin >> cores >> freq >> price; cores = -cores; v.push_back({cores, freq, price}); } sort(v.begin(), v.end(), [&](array<int, 3> a, array<int, 3> b) { if(a[1] == b[1]) { return a[0] > b[0]; } return a[1] > b[1]; }); for(int i = 0; i <= mxN; i++) { dp[i] = NINF; } dp[0] = 0; for(auto it : v) { int cores = it[0], price = it[2]; if(cores > 0) { for(int i = mxN; i >= cores; i--) { if(dp[i-cores] != NINF) { dp[i] = max(dp[i], dp[i-cores] - price); } } } else { for(int i = abs(cores); i <= mxN; i++) { if(dp[i] != NINF) { dp[i+cores] = max(dp[i+cores], dp[i] + price); } } } } ll ans = 0; for(int i = 0; i <= mxN; i++) { ans = max(ans, dp[i]); } cout << ans; 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...