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 long long
using namespace std;
struct Obj{
int rate,cost,nbCores;
};
const int N = 1e5+1, inf = 1e18;
int dp[N];
int32_t main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<Obj> objects;
for (int i=0; i<n; ++i){
int nbCores,rate,cost;
cin >> nbCores >> rate >> cost;
objects.push_back({rate,-cost,nbCores});
}
int m;
cin >> m;
for (int i=0; i<m; ++i){
int nbCores,rate,cost;
cin >> nbCores >> rate >> cost;
objects.push_back({rate,cost,nbCores});
}
sort(objects.begin(),objects.end(),[](const Obj& a, const Obj& b){
if (a.rate != b.rate) return a.rate > b.rate;
return a.cost < b.cost;
});
fill_n(&dp[0],N,-inf);
dp[0] = 0;
for (auto obj:objects){
if (obj.cost < 0){
for (int i=N-1-obj.nbCores; i>=0; --i){
if (dp[i] != -inf) dp[i+obj.nbCores] = max(dp[i+obj.nbCores],dp[i]+obj.cost);
}
}
else{
for (int i=obj.nbCores; i<N; ++i){
if (dp[i] != -inf) dp[i-obj.nbCores] = max(dp[i-obj.nbCores],dp[i]+obj.cost);
}
}
}
int ans = 0;
for (int i=0; i<N; ++i) ans = max(ans,dp[i]);
cout << ans;
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... |