#include <bits/stdc++.h>
using namespace std;
//====== BITWISE ======//
#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)
#define ON(x, i) ((x) | MASK(i))
#define OFF(x, i) ((x) & ~MASK(i))
#define LASTBIT(mask) ((mask) & -(mask))
#define SUBMASK(sub, mask) for (int sub = (mask); sub >= 1; sub = (sub - 1) & (mask))
//====== OTHER ======//
#define fi first
#define se second
#define ll long long
#define endl '\n'
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define mod(x, k) ((((x) % (k)) + (k)) % (k))
#define compress(c) sort(all(c)); c.erase(unique(all(c)), c.end());
#define Longgggg ios_base::sync_with_stdio(0); cin.tie(0);
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for (int i = (a); i >= (b); --i)
//====== FILE ======//
#define IN "A.in"
#define OUT "A.out"
#define DEBUG "debug.out"
//==================//
const int INF = (int) 1e9+5;
const ll LINF = (ll) 1e18;
const ll MOD = (ll) 1e9+7;
const int mxN = (int) 2e5+5;
struct Computer {
int c, f, v, op;
};
// Uu tien may co f lon hon de neu co don can f thi se luon co may du lon de dap ung
bool cmp(Computer &a, Computer &b) {
if (a.f == b.f) return a.op < b.op;
return a.f > b.f;
}
void solve() {
int n; cin >> n;
vector <Computer> a(n);
FOR(i, 1, n) {
int c, f, v; cin >> c >> f >> v;
a.push_back({c, f, v, 1});
}
int m; cin >> m;
FOR(i, 1, m) {
int c, f, v; cin >> c >> f >> v;
a.push_back({c, f, v, 2});
}
sort(all(a), cmp);
vector <ll> dp(mxN+1, -LINF);
dp[0] = 0;
for (auto &x : a) {
int c = x.c, f = x.f, v = x.v, op = x.op;
if (op == 1) {
// Co duoc them c core
FORD(i, mxN, c) if (dp[i-c] != -LINF)
dp[i] = max(dp[i], dp[i-c] - v);
}
else {
// Su dung het c core
FOR(i, 0, mxN-c) if (dp[i+c] != -INF)
dp[i] = max(dp[i], dp[i+c] + v);
}
}
cout << *max_element(all(dp)) << endl;
}
signed main() {
if (fopen(IN, "r")) {
freopen(IN, "r", stdin);
freopen(OUT, "w", stdout);
freopen(DEBUG, "w", stderr);
}
Longgggg
ll t = 1;
// cin >> t;
while (t--) solve();
return 0;
}
Compilation message (stderr)
clo.cpp: In function 'int main()':
clo.cpp:82:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
82 | freopen(IN, "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~
clo.cpp:83:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
83 | freopen(OUT, "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~
clo.cpp:84:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
84 | freopen(DEBUG, "w", stderr);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~
# | 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... |