Submission #1006286

#TimeUsernameProblemLanguageResultExecution timeMemory
1006286makanhuliaCloud Computing (CEOI18_clo)C++17
100 / 100
663 ms2372 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define fi first #define se second #define pb push_back #define pii pair<int, int> #define all(x) x.begin(), x.end() #define ar array<int, 4> bool ckmin(int& a, int b){return b < a ? a = b, 1 : 0;} bool ckmax(int& a, int b){return b > a ? a = b, 1 : 0;} const int N = 2e3 + 5, mod = 1e9 + 7; signed main(){ ios_base::sync_with_stdio(0), cin.tie(0); int n; cin >> n; vector<array<int, 4>> v(4005); for(int i = 0; i < n; i++) cin >> v[i][1] >> v[i][0] >> v[i][2], v[i][3] = 1; int m; cin >> m; for(int i = n; i < n + m; i++) cin >> v[i][1] >> v[i][0] >> v[i][2], v[i][3] = 0; sort(v.begin(), v.begin() + n + m, [&](ar a, ar b) {if(a[0] == b[0]) return a[3] > b[3]; return a[0] > b[0];}); vector<int> dp(1e5 + 5, -1e18); dp[0] = 0; for(int i = 0; i < n + m; i++) { vector<int> next = dp; if(v[i][3]) for(int j = v[i][1]; j <= 1e5; j++) next[j] = max(next[j], dp[j - v[i][1]] - v[i][2]); else for(int j = 0; j <= 1e5 - v[i][1]; j++) next[j] = max(next[j], dp[j + v[i][1]] + v[i][2]); dp = next; } int ans = 0; for(int i = 0; i <= 1e5; i++) ans = max(ans, dp[i]); cout << ans << endl; }
#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...