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;
using i64 = long long;
#define int i64
#define vi vector<int>
#define vvi vector<vi>
#define vb vector<bool>
#define pii pair<int, int>
#define fi first
#define se second
#define sz(x) (int)(x).size()
signed main(){
ios_base::sync_with_stdio(false); cin.tie(0);
int n, m, c, f, v, tot_core = 0;
cin >> n;
vector<array<int, 3>> inp;
for(int i = 0; i < n; i++){
cin >> c >> f >> v;
tot_core += c;
inp.push_back({c, f, -v});
}
cin >> m;
for(int i = 0; i < m; i++){
cin >> c >> f >> v;
inp.push_back({-c, f, v});
}
sort(inp.begin(), inp.end(), [&](array<int, 3> &a, array<int, 3> &b) {return (a[1] == b[1] ? a[2] < b[2] : a[1] > b[1]);} );
vi dp(tot_core + 1, INT64_MIN);
dp[0] = 0;
for(int i = 0; i < sz(inp); i++){
array<int, 3> ar = inp[i];
vi ndp(dp);
for(int c = 0; c <= tot_core; c++){
int nval = c - ar[1];
if(nval >= 0 && nval <= tot_core && dp[nval] != INT64_MIN)
ndp[c] = max(ndp[c], dp[nval] + ar[2]);
}
dp = ndp;
}
cout << *max_element(dp.begin(), dp.end());
return 0;
}
// {number of cores(c), the clock rate(f), the price(v)}
# | 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... |