제출 #963749

#제출 시각아이디문제언어결과실행 시간메모리
963749Art_ogoCloud Computing (CEOI18_clo)C++17
100 / 100
485 ms3924 KiB
#include <bits/stdc++.h> #define ll long long #define fi first #define se second #define ve vector #define all(x) x.begin(), x.end() #define pb(x) push_back(x) using namespace std; mt19937 rnd; typedef pair<ll, ll> pll; typedef pair<int, int> pii; struct cpu{ int c; ll f, v; }; const int MAXN = 4048; const int MAXC = 51*MAXN; ll dp[2][MAXC]; cpu a[2*MAXN]; inline bool comp(const cpu& c1, const cpu& c2){ if(c1.f == c2.f) return c1.c > c2.c; return c1.f > c2.f; } void solve(){ int n; cin >> n; for(int i = 1; i <= n; i++){ cin >> a[i].c >> a[i].f >> a[i].v; a[i].v *= -1; } int m; cin >> m; for(int i = n + 1; i <= n + m; i++){ cin >> a[i].c >> a[i].f >> a[i].v; a[i].c *= -1; } sort(a + 1, a + m + n + 1, comp); fill(dp[0], dp[0] + MAXC, -1e18); fill(dp[1], dp[1] + MAXC, -1e18); dp[0][0] = 0; for(int i = 1; i <= n + m; i++){ int cur = i & 1; int prev = cur ^ 1; for(int j = 0; j < i*51; j++){ dp[cur][j] = dp[prev][j]; if(j - a[i].c >= 0 && j - a[i].c < MAXC) dp[cur][j] = max(dp[cur][j], dp[prev][j - a[i].c] + a[i].v); } } cout << *max_element(dp[(n + m) & 1], dp[(n + m) & 1] + MAXC); } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); int T = 1; // 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...