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;
typedef pair<long long, long long> pll;
typedef pair<int, long long> pil;
typedef pair<long long, int> pli;
typedef pair<int, int> pii;
typedef long double ld;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define in insert
#define ers erase
#define S second
#define F first
const ll inF = 1e18 + 5;
const int N = 1e5 + 5;
int n, m;
ll ans, dp[5][N];
struct strct {
int c, f, v;
};
vector<strct> vec;
int cmp(strct i, strct j){
if (i.f == j.f){
if (i.c > j.c) return 1;
return 0;
}
if (i.f > j.f) return 1;
return 0;
}
void read_input() {
cin >> n;
for (int i = 0; i < n; i++) {
int cc, ff, v;
cin >> cc >> ff >> v;
v *= -1;
strct x;
x.c = cc, x.f = ff, x.v = v;
vec.pb(x);
}
cin >> m;
for (int i = 0; i < m; i++) {
int cc, ff, v;
cin >> cc >> ff >> v;
cc *= (-1);
strct x;
x.c = cc; x.f = ff; x.v = v;
vec.pb(x);
}
sort(vec.begin(), vec.end(), cmp);
}
void solve() {
for (int i = 1; i < N; i++) dp[0][i]= -inF;
for (int i = 0; i < vec.size(); i++) {
for (int j = 0; j < N; j++) {
if (j < vec[i].c) dp[1][j] = dp[0][j];
else if (j - vec[i].c >= N) dp[1][j] = dp[0][j];
else dp[1][j] = max(dp[0][j - vec[i].c] + vec[i].v, dp[0][j]);
}
for (int j = 0; j < N; j++) dp[0][j] = dp[1][j];
}
for (int j = 0; j < N; j++) ans = max(ans, dp[0][j]);
cout << ans << '\n';
}
int main() {
ios :: sync_with_stdio(0), cin.tie(0), cout.tie(0);
read_input(), solve();
return 0;
}
Compilation message (stderr)
clo.cpp: In function 'void solve()':
clo.cpp:61:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<strct>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | for (int i = 0; i < vec.size(); i++) {
| ~~^~~~~~~~~~~~
# | 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... |