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;
#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... |