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 <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
using namespace std;
#define int long long
#define double long double
#define vec vector
#define vi vec<int>
#define pii pair<int,int>
#define vpi vec<pii>
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define pq priority_queue
#define all(v) v.begin(), v.end()
#define FOR(i,a,b) for (int i = a; i < b; i++)
struct Change {
int core_change;
int clock_needed;
int money_change;
Change(int core_change, int clock_needed, int money_change) {
this->core_change = core_change;
this->clock_needed = clock_needed;
this->money_change = money_change;
}
};
vec<Change> t;
vec<vi> dp;
int n, m;
int solve(int idx, int cores_left) {
if (idx >= n + m) return 0;
int &ret = dp[idx][cores_left];
if (ret != -1) return ret;
Change ch = t[idx];
if (cores_left + ch.core_change >= 0) {
ret = max(ret, solve(idx + 1, cores_left + ch.core_change) + ch.money_change);
}
return ret = max(ret, solve(idx + 1, cores_left));
}
signed main() {
cin >> n;
for (int i = 0; i < n; i++) {
int core_count, clock_rate, price_needed;
cin >> core_count >> clock_rate >> price_needed;
t.emplace_back(core_count, clock_rate, -price_needed);
}
cin >> m;
dp.resize(n + m, vi(100000, -1));
for (int i = 0; i < m; i++) {
int core_needed, clock_needed, price_gained;
cin >> core_needed >> clock_needed >> price_gained;
t.emplace_back(-core_needed, clock_needed, price_gained);
}
sort(all(t), [](Change a, Change b) {
return a.clock_needed > b.clock_needed;
});
// for (auto i : t) {
// cout << i.clock_needed << " " << i.core_change << " " << i.money_change << endl;
// }
cout << solve(0, 0) << endl;
}
# | 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... |