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 int long long
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ppb pop_back
#define eb emplace_back
typedef long double ld;
int N, M, f, c, v, idx, idx1, idx2, dp[100005];
tuple<int, int, int> F[100005], S[100005];
pair<int, bool> V[100005];
main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> N;
for (int i = 1, c, f, v; i <= N; i++) {
cin >> c >> f >> v;
F[i] = mt(-f, c, v);
}
cin >> M;
for (int i = 1; i <= M; i++) {
cin >> c >> f >> v;
S[i] = mt(-f, c, v);
}
sort(F + 1, F + 1 + N);
sort(S + 1, S + 1 + M);
for (; idx1 < N && idx2 < M; )
if (get<0>(F[idx1 + 1]) <= get<0>(S[idx2 + 1])) V[++idx] = mp(++idx1, 0);
else V[++idx] = mp(++idx2, 1);
while (idx1 < N) V[++idx] = mp(++idx1, 0);
while (idx2 < M) V[++idx] = mp(++idx2, 1);
for (int i = N + M; i >= 1; i--)
if (V[i].second) for (int j = 100000; j >= get<1>(S[V[i].first]); j--)
dp[j] = max(dp[j], dp[j - get<1>(S[V[i].first])] + get<2>(S[V[i].first]));
else for (int j = 0; j <= 100000 - get<1>(F[V[i].first]); j++)
dp[j] = max(dp[j], dp[j + get<1>(F[V[i].first])] - get<2>(F[V[i].first]));
cout << dp[0] << '\n';
}
Compilation message (stderr)
clo.cpp:15:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main() {
^
# | 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... |