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 pb push_back
#define eb emplace_back
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define uniq(x) x.erase(unique(all(x)), x.end())
#define rall(x) x.rbegin(), x.rend()
//#define int long long
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;
const double eps = 1e-9;
void setIO() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
struct T {
int cores, rate, price;
bool operator<(T &t) {
if(rate == t.rate) return price < t.price;
return rate > t.rate;
}
};
int32_t main() {
setIO();
int n;
cin >> n;
vector<T> v;
v.push_back(T{0, 0, 0});
ll total = 0;
for(int i=0; i<n; i++) {
int a, b, c;
cin >> a >> b >> c;
total += a;
v.push_back(T{a, b, -c});
}
int m;
cin >> m;
for(int i=0; i<m; i++) {
int a, b, c;
cin >> a >> b >> c;
v.push_back(T{-a, b, c});
}
sort(v.begin()+1, v.end());
// for(T &x : v) {
// cout << x.cores << " " << x.rate << " " << x.price << '\n';
// }
vector<vector<ll> > dp(n+m+1, vector<ll>(total+1, -1e10));
dp[0][0] = 0;
for(int i=1; i<=n+m; i++) {
for(int j=0; j<=total; j++) {
dp[i][j] = dp[i-1][j];
if(j - v[i].cores >= 0 && j - v[i].cores <= total && dp[i-1][j-v[i].cores] != -1e10) {
dp[i][j] = max(dp[i][j], dp[i-1][j-v[i].cores] + v[i].price);
}
}
}
ll ans = -1e10;
for(int i=0; i<=total; i++) ans = max(ans, dp[n+m][i]);
cout << ans << '\n';
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... |