# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
582076 | talant117408 | Cloud Computing (CEOI18_clo) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
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;
}
/*
7
4 2
5 7
3 4
6 3
1 3
4 5
*/