제출 #897231

#제출 시각아이디문제언어결과실행 시간메모리
897231vaneaCloud Computing (CEOI18_clo)C++14
100 / 100
350 ms1624 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; for(int i = 0; i < m; i++) { 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]; } else 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]; if(cores > 0) { for(int i = mxN; i >= cores; i--) { if(dp[i-cores] != NINF) { dp[i] = max(dp[i], dp[i-cores]-it[2]); } } } else { for(int i = abs(cores); i <= mxN; i++) { if(dp[i] != NINF) dp[i+cores] = max(dp[i+cores], dp[i]+it[2]); } } } 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...