이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define int long long
struct ComputersAndOrders{
int cores;
int clockSpeed;
int price;
};
int n, m;
vector<ComputersAndOrders> computersAndOrders;
map<pair<int, int>, int> memo;
bool increaseF(const ComputersAndOrders a, const ComputersAndOrders b){
if(abs(a.clockSpeed)==abs(b.clockSpeed)){
return a.cores > b.cores;
}
return abs(a.clockSpeed) > abs(b.clockSpeed);
}
int DP(int x, int computers){
if(memo.find({x, computers}) != memo.end()){
return memo[{x, computers}];
}
if(computers < 0) return -1e10;
if(x== n+m) return 0;
int ans = max(DP(x+1, computers), DP(x+1, computers+computersAndOrders[x].cores)+computersAndOrders[x].price);
memo[{x, computers}] = ans;
return ans;
}
signed main(){
cin >> n;
computersAndOrders.resize(n);
int c, f, v;
for(int i = 0; i <n; i++){
cin >> c >> f >> v;
computersAndOrders[i].cores = c;
computersAndOrders[i].clockSpeed = f;
computersAndOrders[i].price = -v;
}
cin >> m;
computersAndOrders.resize(n+m);
for(int i = 0; i < m; i++){
cin >> c >> f >> v;
computersAndOrders[i+n].cores = -c;
computersAndOrders[i+n].clockSpeed = f;
computersAndOrders[i+n].price = v;
}
sort(computersAndOrders.begin(), computersAndOrders.end(), increaseF);
cout << DP(0, 0) << "\n";
}
# | 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... |