제출 #1006259

#제출 시각아이디문제언어결과실행 시간메모리
1006259devariaotaCloud Computing (CEOI18_clo)C++17
36 / 100
32 ms852 KiB
#include <bits/stdc++.h> using namespace std; # define int long long # define fir first # define sec second # define pb push_back # define endl "\n" const int cnst = 1e4+5; bool mutipletestcase = 0; //bool debug = false; // bool sorting(tuple<int, int, int, bool> a, tuple<int, int, int, bool> b) { // auto[a1, a2, a3, a4] = a; // auto[b1, b2, b3, b4] = b; // return a1 < b1; // } void solve() { int n; cin >> n; vector<tuple<int, int, int, bool>> vec; for(int i = 1; i<=n; i++) { int a, b, c; cin >> a >> b >> c; vec.pb({b, a, c, 0}); } int m; cin >> m; for(int i = 1; i<=m; i++) { int a, b, c; cin >> a >> b >> c; vec.pb({b, a, c, 1}); } sort(vec.begin(), vec.end()); reverse(vec.begin(), vec.end()); int dp[cnst]; dp[0] = 0; for(int i = 1; i<=1e4; i++) dp[i] = 1e18*-1; for(auto [pow, fre, cos, id]: vec) { if(!id) { for(int i = 1e4; i>=fre; i--) dp[i] = max(dp[i], dp[i-fre]-cos); } else { for(int i = 0; i<=1e4-fre; i++) dp[i] = max(dp[i], dp[i+fre]+cos); } // for(int i = 1; i<=10; i++) cerr << dp[i] << " "; cerr << endl; } int ans = 0; for(int i = 0; i<=1e4; i++) ans = max(ans, dp[i]); cout << ans << endl; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); int t = 1; if(mutipletestcase) cin >> t; while(t--) solve(); }
#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...