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>
#define int int64_t //be careful about this
using namespace std;
struct item{
int type,cores,clock_rate,value;
};
signed main(){
int n;
cin >> n;
vector<item> items;
while(n--){
int c,f,v;
cin >> c >> f >> v;
items.push_back({0,c,f,v});
}
int m;
cin >> m;
while(m--){
int c,f,v;
cin >> c >> f >> v;
items.push_back({1,c,f,v});
}
sort(items.begin(), items.end(),[&](auto l,auto r){
return l.clock_rate == r.clock_rate ? l.type > r.type : l.clock_rate < r.clock_rate;
});
auto upd = [&](vector<int>& dp,int i,int profit){
while(int(dp.size()) <= i)
dp.push_back(-1e16);
if(dp[i] < profit)
dp[i] = profit;
};
vector<int> dp;
upd(dp,0,0);
for(auto [type,cores,clock_rate,value] : items){
vector<int> ndp = dp;
for(int need = 0; need < int(dp.size()); ++need){
int new_need = max(int(0),need + (type == 0 ? -1 : +1) * cores);
int new_profit = dp[need] + (type == 0 ? -1 : +1) * value;
upd(ndp,new_need,new_profit);
}
dp = ndp;
}
cout << dp[0];
return 0;
}
# | 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... |