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 rep(i, a, b) for (int i = a; i < (b); ++i)
#define per(i, a, b) for (int i = b - 1; i >= (a); --i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define pb push_back
#define umap unordered_map
#define uset unordered_set
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef long long ll;
const int INF = 1000000007;
const ll llinf = 1000000000000000;
int main() {
int n, m, c, f, sumc = 1;
vector<pair<ii, pair<ll, int>>> dpvec;
ll v, ans = 0;
scanf("%d", &n);
rep(i, 0, n) {
scanf("%d %d %lld", &c, &f, &v);
dpvec.push_back({{f, 1}, {v, c}});
sumc += c;
}
scanf("%d", &m);
rep(i, 0, m) {
scanf("%d %d %lld", &c, &f, &v);
dpvec.push_back({{f, 0}, {v, c}});
}
sort(all(dpvec), greater<>());
vector<ll> dp(sumc, -llinf);
dp[0] = 0;
sumc = 1;
trav(item, dpvec) {
int query;
query = item.first.second;
tie(v, c) = item.second;
if (!query)
rep(i, c, sumc) {
if (dp[i] == -llinf) continue;
dp[i - c] = max(dp[i - c], dp[i] + v);
}
else {
per(i, 0, sumc) {
if (dp[i] == -llinf) continue;
dp[i + c] = max(dp[i + c], dp[i] - v);
}
sumc += c;
}
}
trav(val, dp) ans = max(ans, val);
printf("%lld\n", ans);
return 0;
}
Compilation message (stderr)
clo.cpp: In function 'int main()':
clo.cpp:31:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
31 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
clo.cpp:33:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
33 | scanf("%d %d %lld", &c, &f, &v);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
38 | scanf("%d", &m);
| ~~~~~^~~~~~~~~~
clo.cpp:40:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
40 | scanf("%d %d %lld", &c, &f, &v);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |