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;
struct Transaction {
int cores;
int rate;
int price;
};
int main() {
vector<Transaction> poss_transactions;
int max_computers = 0;
int comp_num;
cin >> comp_num;
for (int c = 0; c < comp_num; c++) {
Transaction trans;
cin >> trans.cores >> trans.rate >> trans.price;
trans.price = -trans.price;
poss_transactions.push_back(trans);
max_computers += trans.cores;
}
int order_num;
cin >> order_num;
for (int o = 0; o < order_num; o++) {
Transaction trans;
cin >> trans.cores >> trans.rate >> trans.price;
trans.cores = -trans.cores;
poss_transactions.push_back(trans);
}
sort(poss_transactions.begin(), poss_transactions.end(),
[](const Transaction &a, const Transaction &b) -> bool {
return a.rate != b.rate ? a.rate > b.rate : a.price < b.price;
});
vector<long long> max_profits(max_computers + 1, INT64_MIN);
max_profits[0] = 0;
for (const Transaction &t : poss_transactions) {
vector<long long> new_max(max_profits);
for (int c = 0; c <= max_computers; c++) {
int prev_comp = c - t.cores;
if (0 <= prev_comp && prev_comp <= max_computers &&
max_profits[prev_comp] != INT64_MIN) {
new_max[c] =
max(new_max[c], max_profits[prev_comp] + t.price);
}
}
max_profits = new_max;
}
cout << *max_element(max_profits.begin(), max_profits.end()) << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |