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;
#define lli long long int
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define X first
#define Y second
#define pii pair<int,int>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
void abc() {cout << endl;}
template <typename T, typename ...U> void abc(T i, U ...j) {
cout << i << ' ', abc(j...);
}
template <typename T> void printv(T l, T r) {
for (; l != r; ++l)
cout << *l << " \n"[l + 1 == r];
}
#ifdef Doludu
#define test(x...) abc("[" + string(#x) + "]", x);
#define owo freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#else
#define test(x...) void(0);
#define owo ios::sync_with_stdio(false), cin.tie(0)
#endif
const int N = 200000;
struct item {
int c, f, v;
};
int main () {
owo;
int n, m;
cin >> n;
vector <item> a(n);
for (int i = 0; i < n; ++i)
cin >> a[i].c >> a[i].f >> a[i].v;
cin >> m;
vector <item> b(m);
for (int i = 0; i < m; ++i)
cin >> b[i].c >> b[i].f >> b[i].v;
int S1 = n * 50 + 1, S2 = m * 50 + 1;
vector <lli> dp1(S1, 1ll << 60), dp2(S2);
dp1[0] = 0;
for (int i = 0; i < n; ++i) {
for (int j = S1 - a[i].c - 1; ~j; --j) {
dp1[j + a[i].c] = min(dp1[j + a[i].c], dp1[j] + a[i].v);
}
}
for (int i = 0; i < m; ++i) {
for (int j = S2 - b[i].c - 1; ~j; --j) {
dp2[j + b[i].c] = max(dp2[j + b[i].c], dp2[j] + b[i].v);
}
}
lli ans = 0;
for (int i = 0; i < min(S1, S2); ++i)
ans = max(ans, dp2[i] - dp1[i]);
cout << ans << 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... |