Submission #821867

#TimeUsernameProblemLanguageResultExecution timeMemory
821867NK_Cloud Computing (CEOI18_clo)C++17
100 / 100
348 ms1236 KiB
// Success consists of going from failure to failure without loss of enthusiasm #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("sse") #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 int nax = int(1e5) + 5; ll dp[nax]; 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)); memset(dp, -1, sizeof dp); dp[0] = 0; for(int i = 0; i < N + M; i++) { if (A[i][1] == -1) { int c = A[i][2], v = A[i][3]; for(int x = nax - 1; x >= 0; x--) if (dp[x] != -1) { int y = x + c; if (y < nax) dp[y] = max(dp[x] + v, dp[y]); } } else { int c = A[i][2], v = A[i][3]; int y; for(int x = 0; x < nax; x++) if (dp[x] != -1) { if (x < c) y = 0; else y = x - c; 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...