이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
struct Transaction {
int cores;
int rate;
int price;
};
int main() {
vector<Transaction> poss_transactions; //possible transactions
int max_CPUS = 0; //max # of CPUS
int N; cin >> N; //# of computers available
for(int x=0; x<N; x++) {
Transaction trans;
cin >> trans.cores >> trans.rate >> trans.price;
trans.price = -trans.price;
poss_transactions.push_back(trans);
max_CPUS += trans.cores;
}
int M; cin >> M; //# of orders from customers
for(int y=0; y<M; y++) {
Transaction trans;
cin >> trans.cores >> trans.rate >> trans.price;
trans.cores = -trans.cores;
poss_transactions.push_back(trans);
}
//The clock rate issue goes away if we process the orders in order.
sort(
poss_transactions.begin(), poss_transactions.end(),
[](const Transaction& a, const Transaction& b) {
return a.rate != b.rate ? a.rate > b.rate : a.price < b.price;
});
/*
* max_profits[t][c] = the maximum profit we can gain from the first
* t transactions given that we have c cores left
*/
vector<long long> max_profits(max_CPUS+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_CPUS; c++) {
int prev_comp = c - t.cores;
if(0 <= prev_comp && prev_comp <= max_CPUS
&& 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... |