Submission #1006285

#TimeUsernameProblemLanguageResultExecution timeMemory
1006285christinelynnCloud Computing (CEOI18_clo)C++17
72 / 100
647 ms2392 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) {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...