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 ll = long long;
using ld = long double;
using pii = pair<int, int>;
#define rep(i, n) for (int (i) = 0; (i) < (n); ++(i))
#define all(x) (x).begin(), (x).end()
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int MAXN = 2e3 + 5;
struct item {
int c, f, p;
bool t;
};
bool operator<(const item &a, const item &b) {
if (a.f == b.f) return a.t < b.t;
return a.f > b.f;
}
int n, m;
vector<item> a;
ll dp[MAXN * 55];
int main() {
FAST_IO;
cin >> n;
rep(i, n) {
int c, f, p;
cin >> c >> f >> p;
a.push_back({c, f, -p, 0});
}
cin >> m;
rep(i, m) {
int c, f, p;
cin >> c >> f >> p;
a.push_back({-c, f, p, 1});
}
n = a.size();
sort(all(a));
fill(dp, dp + MAXN * 55, -1e18);
dp[0] = 0;
rep(i, n) {
auto [c, f, p, t] = a[i];
if (c < 0) {
for (int i = 0; i - c < MAXN * 55; ++i) {
dp[i] = max(dp[i], dp[i - c] + p);
}
} else {
for (int i = MAXN * 55 - 1; i - c >= 0; --i) {
dp[i] = max(dp[i], dp[i - c] + p);
}
}
}
ll res = 0;
for (int i = 0; i < MAXN * 55; ++i) {
res = max(res, dp[i]);
}
cout << res << endl;
}
Compilation message (stderr)
clo.cpp: In function 'int main()':
clo.cpp:49:14: warning: decomposition declaration only available with -std=c++1z or -std=gnu++1z
auto [c, f, p, t] = a[i];
^
clo.cpp:49:25: warning: unused variable 'f' [-Wunused-variable]
auto [c, f, p, t] = a[i];
^
clo.cpp:49:25: warning: unused variable 't' [-Wunused-variable]
# | 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... |