제출 #417039

#제출 시각아이디문제언어결과실행 시간메모리
417039egekabasCloud Computing (CEOI18_clo)C++14
36 / 100
3070 ms3792 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; }; ll sf(st a, st b){ return a.f > b.f; } 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); sort(b, b+m, sf); for(ll j = 0; j <= m; ++j) for(ll k = 0; k <= 100; ++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 <= 100; ++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 <= 100){ 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 <= 100) 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 <= 100; ++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...