Submission #376414

#TimeUsernameProblemLanguageResultExecution timeMemory
376414jakubdCloud Computing (CEOI18_clo)C++17
100 / 100
436 ms1516 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> orderedSet; typedef tree<long long, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> orderedMultiset; #define pb push_back #define mp make_pair #define sz(x) ((int)x.size()) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define manytests int TT;cin >> TT; while (TT--) #define FOR(i,a,b) for (long long i = (a); i < (b); ++i) #define FORd(i,a,b) for (long long i = (a); i >= (b); --i) # define M_PI 3.14159265358979323846 int dx[8] = {-1, 1, 0, 0, 1, 1, -1, -1}, dy[8] = {0, 0, 1, -1, 1, -1, 1, -1}; #define ll long long #define ld long double #define fi first #define se second #define rev reverse #define vi vector<int> #define vl vector<ll> #define vc vector<char> #define vd vector<double> #define vs vector<string> #define vld vector<ld> #define vb vector<bool> #define vvi vector<vi> #define vvl vector<vl> #define pii pair<int, int> #define pll pair<ll, ll> #define pld pair<ld, ld> #define vpi vector<pii> #define vpl vector<pll> #define vpld vector<pld> struct Event { ll cores, freq, value, id; Event(ll _cores, ll _freq, ll _value, ll _id): cores(_cores), freq(_freq), value(_value), id(_id) {} bool operator<(const Event& other) const { if (freq != other.freq) return freq > other.freq; return id < other.id; } }; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n; cin >> n; vector<Event> events; ll al = 0; FOR(i,0,n) { ll a, b, c; cin >> a >> b >> c; al += a; events.pb(Event(a, b, c, -1)); } ll m; cin >> m; FOR(i,0,m) { ll a, b, c; cin >> a >> b >> c; events.pb(Event(a, b, c, i)); } sort(all(events)); vl dp(al + 1, -1e15); dp[0] = 0; for (auto e : events) { if (e.id == -1) for (int i = al; i >= e.cores; i--) dp[i] = max(dp[i], dp[i - e.cores] - e.value); else for (int i = 0; i <= al - e.cores; i++) dp[i] = max(dp[i], dp[i + e.cores] + e.value); } cout << *max_element(all(dp)) << "\n"; 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...