제출 #550113

#제출 시각아이디문제언어결과실행 시간메모리
550113JomnoiCloud Computing (CEOI18_clo)C++17
100 / 100
419 ms1312 KiB
#include <bits/stdc++.h> #define DEBUG false using namespace std; const int MAX_C = 1e5 + 10; const long long INF = 1e18 + 7; long long dp[MAX_C + 1]; class Computer { public : int c, f, v, t; Computer() {} Computer(const int &c_, const int &f_, const int &v_, const int &t_) : c(c_), f(f_), v(v_), t(t_) {} bool operator<(const Computer &o) const { return make_pair(f, -t) > make_pair(o.f, -o.t); } }; int main() { cin.tie(nullptr)->sync_with_stdio(false); int n; cin >> n; vector <Computer> vec; for(int i = 1; i <= n; i++) { int c, f, v; cin >> c >> f >> v; vec.push_back(Computer(c, f, v, -1)); } int m; cin >> m; for(int i = 1; i <= m; i++) { int c, f, v; cin >> c >> f >> v; vec.push_back(Computer(c, f, v, 1)); } sort(vec.begin(), vec.end()); for(int i = 0; i <= MAX_C; i++) { dp[i] = -INF; } dp[0] = 0; for(auto [c, f, v, t] : vec) { if(t == -1) { for(int C = MAX_C; C >= c; C--) { dp[C] = max(dp[C], dp[C - c] - v); } } else { for(int C = 0; C <= MAX_C - c; C++) { dp[C] = max(dp[C], dp[C + c] + v); } } } long long ans = 0; for(int i = 0; i <= MAX_C; 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...