제출 #821845

#제출 시각아이디문제언어결과실행 시간메모리
821845NK_Cloud Computing (CEOI18_clo)C++17
100 / 100
425 ms1300 KiB
// Success consists of going from failure to failure without loss of enthusiasm #include <bits/stdc++.h> using namespace std; #define nl '\n' #define pb push_back using ll = long long; template<class T> using V = vector<T>; using vi = V<int>; using vl = V<ll>; const ll INF = ll(1e15) + 10; int main() { cin.tie(0)->sync_with_stdio(0); int N; cin >> N; V<array<int, 4>> A; for(int i = 0; i < N; i++) { int c, f, v; cin >> c >> f >> v; A.pb({f, 1, c, v}); } int M; cin >> M; for(int i = 0; i < M; i++) { int c, f, v; cin >> c >> f >> v; A.pb({f, -1, c, v}); } sort(begin(A), end(A)); const int nax = N * 50 + 5; vl dp(nax, -INF); dp[0] = 0; for(int i = 0; i < N + M; i++) { V<array<ll, 2>> S, B; int j = i; while(j < N + M && A[j][0] == A[i][0]) { if (A[j][1] == -1) S.pb({A[j][2], A[j][3]}); else B.pb({A[j][2], A[j][3]}); j++; } i = j - 1; for(auto s : S) { auto [c, v] = s; for(int x = nax - 1; x >= 0; x--) if (dp[x] != -INF) { int y = x + c; if (y < nax) dp[y] = max(dp[x] + v, dp[y]); } } for(auto s : B) { auto [c, v] = s; for(int x = 0; x < nax; x++) if (dp[x] != -INF) { int y = max(x - int(c), 0); dp[y] = max(dp[x] - v, dp[y]); } } } cout << dp[0] << nl; return 0; }
#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...