Submission #943644

#TimeUsernameProblemLanguageResultExecution timeMemory
943644iskhakkutbilimCloud Computing (CEOI18_clo)C++17
100 / 100
607 ms2296 KiB
#include <bits/stdc++.h> using namespace std; #define ff first #define ss second #define all(a) a.begin(), a.end() #define int long long const int N = 2e5; const int mod = 1e16 + 7; signed main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; vector<array<int, 4> > w; for(int i = 0;i < n; i++){ int c, f, cost; cin >> c >> f >> cost; w.push_back({c, f, cost, 1}); } int m; cin >> m; for(int i = 0;i < m; i++){ int c, f, cost; cin >> c >> f >> cost; w.push_back({c, f, cost, 0}); } sort(all(w), [&](auto A, auto B){ if(A[1] == B[1]) return A[3] > B[3]; return A[1] > B[1]; }); vector<int> dp(N+5, -mod); dp[0] = 0; for(auto [c, f, cost, type] : w){ if(type == 1){ for(int i = N; i >= c; i--){ dp[i] = max(dp[i], dp[i-c] - cost); } }else{ for(int i = 0; i <= N - c; i++){ dp[i] = max(dp[i], dp[i+c] + cost); } } } cout << *max_element(all(dp)); 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...