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>
#define task "C"
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (int i = (r); i >= (l); --i)
#define DB(X) { cerr << #X << " = " << (X) << '\n'; }
#define DB1(A, _) { cerr << #A << "[" << _ << "] = " << (A[_]) << '\n'; }
#define DB2(A, _, __) { cerr << #A << "[" << _ << "][" << __ << "] = " << (A[_][__]) << '\n'; }
#define DB3(A, _, __, ___) { cerr << #A << "[" << _ << "][" << __ << "][" << ___ << "] = " << (A[_][__][___]) << '\n'; }
#define PR(A, l, r) { cerr << '\n'; rep(_, l, r) DB1(A, _); cerr << '\n';}
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
#define pf push_front
#define F first
#define S second
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a));
#define next ___next
#define prev ___prev
#define y1 ___y1
#define left ___left
#define right ___right
#define y0 ___y0
#define div ___div
#define j0 ___j0
#define jn ___jn
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;
const int N = 2003;
int n, m;
ll dp[2][N * 50];
struct Item
{
int cores, val, fr;
Item() {}
Item(int c, int f, int v) : cores(c), fr(f), val(v) {}
bool operator < (const Item &oth)
{
return (fr > oth.fr) || (fr == oth.fr && cores > oth.cores);
}
};
vector<Item> order;
int main()
{
#ifdef HynDuf
freopen(task".in", "r", stdin);
//freopen(task".out", "w", stdout);
#else
ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif
cin >> n;
int mxCores = 0;
rep(i, 1, n)
{
int c, f, v;
cin >> c >> f >> v;
order.pb(Item(c, f, -v));
mxCores += c;
}
cin >> m;
rep(i, 1, m)
{
int c, f, v;
cin >> c >> f >> v;
order.pb(Item(-c, f, v));
}
sort(all(order));
rep(i, 1, mxCores) dp[0][i] = -1e18;
int now = 0, lst = 1;
for (Item I : order)
{
swap(now, lst);
rep(i, 0, mxCores) dp[now][i] = dp[lst][i];
rep(numCores, 0, mxCores)
{
if (numCores >= I.cores && numCores - I.cores <= mxCores)
dp[now][numCores] = max(dp[now][numCores], dp[lst][numCores - I.cores] + I.val);
}
}
ll ans = 0;
rep(numCores, 1, mxCores) ans = max(ans, dp[now][numCores]);
cout << ans;
return 0;
}
Compilation message (stderr)
clo.cpp: In constructor 'Item::Item(int, int, int)':
clo.cpp:43:21: warning: 'Item::fr' will be initialized after [-Wreorder]
int cores, val, fr;
^~
clo.cpp:43:16: warning: 'int Item::val' [-Wreorder]
int cores, val, fr;
^~~
clo.cpp:45:5: warning: when initialized here [-Wreorder]
Item(int c, int f, int v) : cores(c), fr(f), val(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... |