Submission #582080

#TimeUsernameProblemLanguageResultExecution timeMemory
582080talant117408Cloud Computing (CEOI18_clo)C++17
100 / 100
344 ms1364 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair <int, int> pii; typedef pair <ll, ll> pll; #define pb push_back #define mp make_pair #define all(v) (v).begin(),(v).end() #define rall(v) (v).rbegin(),(v).rend() #define lb lower_bound #define ub upper_bound #define sz(v) int((v).size()) #define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define endl '\n' struct event { ll rate, value; int cores, id; event(int _cores, ll _rate, ll _value, int _id) { cores = _cores; rate = _rate; value = _value; id = _id; } bool operator <(event other) { if (rate == other.rate) return id < other.id; return rate > other.rate; } }; void solve() { int n, m; cin >> n; vector <event> tasks; int cores_available = 0; for (int i = 0; i < n; i++) { int cores; ll rate, value; cin >> cores >> rate >> value; cores_available += cores; tasks.pb(event(cores, rate, value, -1)); } cin >> m; for (int i = 0; i < m; i++) { int cores; ll rate, value; cin >> cores >> rate >> value; tasks.pb(event(cores, rate, value, i)); } vector <ll> dp(cores_available+1, -2e18); dp[0] = 0; sort(all(tasks)); for (auto X : tasks) { int cores = X.cores, id = X.id; ll value = X.value; if (id == -1) { for (int i = cores_available; i >= cores; i--) { dp[i] = max(dp[i], dp[i-cores] - value); } } else { for (int i = 0; i <= cores_available-cores; i++) { dp[i] = max(dp[i], dp[i+cores] + value); } } } cout << *max_element(all(dp)); } int main() { do_not_disturb int t = 1; //~ cin >> t; while (t--) { solve(); } 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...