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 <iostream>
#include <string>
#include <string.h>
#include <fstream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include<map>
#include <stack>
#include <unordered_map>
#include <set>
#define ll long long
#define For(i, n) for(ll i = 0; i < n; i++)
#define ffor(i, a, n) for(ll i = a; i < n; i++)
#define pb push_back
#define vec vector
#define ff first
#define ss second
#define pairs pair<ll, ll>
#define NEK 1000000000000000000
#define mod 1000000007
using namespace std;
struct tr {
ll p, h, c;
};
bool zorad(tr a, tr b) {
if (a.h == b.h) {
return a.p > b.p;
}
return a.h > b.h;
}
vec<ll> sitko(ll n) {
vec<bool> A;
A.resize(n - 2 + 1, true);
for (ll i = 2; i * i <= n; i++) {
if (A[i - 2]) {
for (ll j = i * i; j <= n; j += i) {
A[j - 2] = false;
}
}
}
vec<ll> prv;
For(i, A.size()) {
if (A[i]) {
prv.push_back(i + 2);
}
}
return prv;
}
int main() {
ll n;
cin >> n;
vec<tr> p;
ll c1 = 0;
ll c2 = 0;
For(i, n) {
ll x, y, z;
cin >> x >> y >> z;
p.push_back({ x, y, -z });
c1 += x;
}
ll m;
cin >> m;
vec<tr> o;
For(i, m) {
ll x, y, z;
cin >> x >> y >> z;
o.push_back({ -x, y, z });
c2 += x;
}
vec<tr> v;
For(i, n) {
v.push_back(p[i]);
}
For(i, m) {
v.push_back(o[i]);
}
sort(v.begin(), v.end(), zorad);
ll cc = c1+1;
vec<vec<ll>> dp(2, vec<ll>(cc, (-1)*NEK));
dp[0][0] = 0;
ffor(i, 1, dp.size()) {
ll now = i % 2;
ll last = 1 - now;
For(j, cc) {
if ((j - v[i - 1].p) < 0 || (j - v[i - 1].p) >= dp[now].size()) {
dp[now][j] = dp[last][j];
}
else {
dp[now][j] = max(dp[last][j], dp[last][j - v[i - 1].p] + v[i - 1].c);
}
}
}
ll naj = -1;
ll nov = (dp.size() - 1) % 2;
For(i, cc) {
naj = max(naj, dp[nov][i]);
}
cout << naj << endl;
return 0;
}
Compilation message (stderr)
clo.cpp: In function 'std::vector<long long int> sitko(long long int)':
clo.cpp:14:35: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
14 | #define For(i, n) for(ll i = 0; i < n; i++)
......
47 | For(i, A.size()) {
| ~~~~~~~~~~~
clo.cpp:47:2: note: in expansion of macro 'For'
47 | For(i, A.size()) {
| ^~~
clo.cpp: In function 'int main()':
clo.cpp:15:39: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
15 | #define ffor(i, a, n) for(ll i = a; i < n; i++)
......
89 | ffor(i, 1, dp.size()) {
| ~~~~~~~~~~~~~~~
clo.cpp:89:2: note: in expansion of macro 'ffor'
89 | ffor(i, 1, dp.size()) {
| ^~~~
clo.cpp:93:49: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
93 | if ((j - v[i - 1].p) < 0 || (j - v[i - 1].p) >= dp[now].size()) {
| ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
# | 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... |