이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |