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 ll long long
using namespace std;
struct in{
int rate, cores, price;
};
bool cmp(in x, in y){
return x.rate != y.rate ? x.rate > y.rate : x.price < y.price;
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
int N; cin >> N;
vector<in> inputs; int corenum = 0;
for(int i = 0;i<N;++i){
int c,f,v; cin >> c >> f >> v; corenum += c;
inputs.push_back({f,c,-v});
}
int M; cin >> M;
for(int i = 0;i<M;++i){
int c,f,v; cin >> c >> f >> v;
inputs.push_back({f,-c,v});
}
sort(inputs.begin(),inputs.end(),cmp);
vector<ll> dp(corenum+1,INT64_MIN); dp[0] = 0;
for(auto p : inputs){
vector<ll> answer(dp);
for(int i = 0;i<=corenum;++i){
int prev = i-p.cores;
if(prev >= 0 && prev <= corenum && dp[prev] != INT64_MIN){
answer[i] = max(answer[i],dp[prev]+p.price);
}
}
dp = answer;
}
cout << *max_element(dp.begin(),dp.end());
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... |