# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
486557 | john256 | Cloud Computing (CEOI18_clo) | C++11 | 0 ms | 0 KiB |
이 제출은 이전 버전의 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 maxC = 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);
maxC += 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;
});
/*
* dp[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(maxC+1, INT64_MIN);
dp[0] = 0;
for(const Transaction& t : poss_transactions) {
vector<long long> dp2(dp); //updated dp array after transaction t
for(int c=0; c<=maxC; c++) {
int prev_comp = c - t.cores;
if(0 <= prev_comp && prev_comp <= maxC
&& dp[prev_comp] != INT64_MIN) {
dp2[c] = max(dp2[c], dp[prev_comp] + t.price);
}
}
dp = dp2;
}
cout << *max_element(dp.begin(), dp.end()) << endl;
}