Submission #1143053

#TimeUsernameProblemLanguageResultExecution timeMemory
1143053DON_FCloud Computing (CEOI18_clo)C++20
72 / 100
575 ms2064 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; #define all(x) x.begin(), x.end() #define L(i, b, e) for (int i = b; i < e; ++i) #define R(i, b, e) for (int i = b; i >= e; --i) #define pb emplace_back #define vi vector<int> #define sz(x) ((int) x.size()) const int N = 2e3 + 7, Mx = 1e9 + 9; int n, m; struct info{ int c, f, v, ty; } a[2 * N]; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n; L(i, 0, n){ cin >> a[i].c >> a[i].f >> a[i].v; a[i].ty = 1; } cin >> m; L(i, n, n + m){ cin >> a[i].c >> a[i].f >> a[i].v; a[i].ty = 2; } sort(a, a + n + m, [&](const info &cm, const info &cp){ return cm.f > cp.f; }); vector<ll> dp(50 * n + 7, -1LL * Mx * Mx); dp[0] = 0; L(i, 0, n + m){ vector<ll> ndp(50 * n + 7, -1LL * Mx * Mx); L(j, 0, 50 * n + 1){ if (dp[j] == -1LL * Mx * Mx)continue; if (a[i].ty == 1){ ndp[j + a[i].c] = max(ndp[j + a[i].c], dp[j] - a[i].v); }else if (j >= a[i].c){ ndp[j - a[i].c] = max(ndp[j - a[i].c], dp[j] + a[i].v); } ndp[j] = max(ndp[j], dp[j]); } swap(dp, ndp); } ll ans = 0; L(j, 0, 50 * n + 1)ans = max(ans, dp[j]); cout << ans; }
#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...