Submission #1007149

#TimeUsernameProblemLanguageResultExecution timeMemory
1007149makanhuliaCloud Computing (CEOI18_clo)C++17
0 / 100
4 ms1116 KiB
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") typedef long long ll; const ll INF = 1e15; const ll MOD = 1e9 + 7; const ll MAXN = 2e3 + 5; const ll LOG = 31; #define vll vector <ll> #define pll pair <ll, ll> #define fi first #define se second #define endl '\n' ll n, m, d; pll a [MAXN], b [MAXN]; ll dp [50*MAXN]; vector <array <ll, 3>> ab; void solve(){ cin >> n; ab.push_back({-INF, 0, 0}); for(ll i = 1; i <= n; i++){ ll c, f, v; cin >> c >> f >> v; a[i] = {c, v}; ab.push_back({-f, 0, i}); } cin >> m; for(ll i = 1; i <= m; i++){ ll c, f, v; cin >> c >> f >> v; b[i] = {c, v}; ab.push_back({-f, 1, i}); } sort(ab.begin(), ab.end()); for(ll j = 0; j < 50*MAXN; j++) dp[j] = -INF; dp[0] = 0; ll ans = -INF; // for(ll i = 1; i <= n+m; i++){ // cout << ab[i][0] << " " << ab[i][1] << " " << ab[i][2] << endl; // } for(ll i = 1; i <= n+m; i++){ if(ab[i][1]){ ll c = b[ab[i][2]].fi, v = b[ab[i][2]].se; for(ll j = 50*MAXN-1; j >= 0; j--){ if(j+c < 50*MAXN) dp[j] = max(dp[j], dp[j+c] + v); ans = max(ans, dp[j]); } } else{ ll c = a[ab[i][2]].fi, v = a[ab[i][2]].se; for(ll j = 0; j < 50*MAXN; j++){ if(j-c >= 0) dp[j] = max(dp[j], dp[j-c] - v); ans = max(ans, dp[j]); } } // for(ll j = 0; j <= 40; j++){ // cout << dp[j] << " "; // } // cout << endl; } cout << ans << endl; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // ll t; 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...