Submission #949459

#TimeUsernameProblemLanguageResultExecution timeMemory
949459glebustimCloud Computing (CEOI18_clo)C++17
100 / 100
307 ms1624 KiB
#include <bits/extc++.h> using namespace std; using namespace __gnu_pbds; #define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define all(a) a.begin(), a.end() using ll = long long; using ld = long double; using pii = pair<int, int>; using vi = vector<int>; using oset = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>; const ll INF = 1e18 + 100; const int N = 1e5 + 10; int main() { fast; vector<tuple<int, int, int>> a; int n; cin >> n; for (int i = 0; i < n; ++i) { int c, f, v; cin >> c >> f >> v; a.emplace_back(f, c, v); } int m; cin >> m; for (int i = 0; i < m; ++i) { int c, f, v; cin >> c >> f >> v; a.emplace_back(f, -c, v); } sort(all(a)); reverse(all(a)); ll d[N]; d[0] = 0; for (int i = 1; i < N; ++i) d[i] = -INF; for (auto [f, c, v]: a) { if (c > 0) { for (int i = N - 1; i >= c; --i) d[i] = max(d[i], d[i - c] - v); } else { for (int i = -c; i < N; ++i) d[i + c] = max(d[i + c], d[i] + v); } } ll ans = 0; for (int i = 0; i < N; ++i) ans = max(ans, d[i]); 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...