Submission #417100

#TimeUsernameProblemLanguageResultExecution timeMemory
417100egekabasCloud Computing (CEOI18_clo)C++14
72 / 100
2117 ms3840 KiB
#include <bits/stdc++.h> #define all(x) (x).begin(), (x).end() #define ff first #define ss second #define pb push_back #define mp make_pair using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<ll, ll> pll; typedef pair<ull, ull> pull; typedef pair<ll, ll> pii; typedef pair<ld, ld> pld; const ll inf = 1e17; struct st{ ll c, f, v; }; int sfst = 0; ll sf(st a, st b){ if(a.f != b.f) return a.f > b.f; return ld(a.v)/a.c < ld(b.v)/b.c; } ll n, m; st a[2009]; st b[2009]; ll dp[2001][109]; ll nxt[2001][109]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); cin >> n; for(ll i = 0; i < n; ++i) cin >> a[i].c >> a[i].f >> a[i].v; cin >> m; for(ll i = 0; i < m; ++i) cin >> b[i].c >> b[i].f >> b[i].v; sort(a, a+n, sf); sfst = 1; sort(b, b+m, sf); for(ll j = 0; j <= m; ++j) for(ll k = 0; k <= 55; ++k) dp[j][k] = nxt[j][k] = -inf; dp[0][0] = 0; ll ans = 0; for(ll i = 0; i < n; ++i){ for(ll j = 0; j < m; ++j) for(ll k = 0; k <= 55; ++k){ nxt[j][k] = max(nxt[j][k], dp[j][k]); dp[j+1][k] = max(dp[j+1][k], dp[j][k]); if(k >= b[j].c) dp[j+1][k-b[j].c] = max(dp[j+1][k-b[j].c], dp[j][k]+b[j].v); if(a[i].f >= b[j].f){ if(k+a[i].c <= 55){ nxt[j][k+a[i].c] = max(nxt[j][k+a[i].c], dp[j][k]-a[i].v); } if(k+a[i].c-b[j].c >= 0 && k+a[i].c-b[j].c <= 55) nxt[j+1][k+a[i].c-b[j].c] = max(nxt[j+1][k+a[i].c-b[j].c], dp[j][k]-a[i].v+b[j].v); } } for(ll j = 0; j <= m; ++j) for(ll k = 0; k <= 55; ++k){ ans = max(ans, nxt[j][k]); ans = max(ans, dp[j][k]); dp[j][k] = nxt[j][k]; nxt[j][k] = -inf; } } cout << ans << '\n'; }
#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...