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 ll long long
#define pii pair<int, int>
#define pli pair<int, pii>
#define fi first
#define se second
const int MN = 1e5 + 10;
const ll INF = 1e18;
int N, M;
ll dp[2][MN];
vector<pli> vec;
void chmax(ll& a, ll b){
if(b > a) a = b;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> N;
for(int i = 0; i < N; i++){
int c, f, v; cin >> c >> f >> v;
vec.push_back({f, {c, -v}});
}
cin >> M;
for(int i = 0; i < M; i++){
int c, f, v; cin >> c >> f >> v;
vec.push_back({f, {-c, v}});
}
int sz = vec.size();
sort(vec.begin(), vec.end(), greater<pli>());
dp[0][0] = 0;
for(int j = 1; j < MN; j++) dp[0][j] = -INF;
int id = 1;
for(int i = 0; i < sz; i++){
for(int j = 0; j < MN; j++){
dp[id][j] = dp[id ^ 1][j];
int pre = j - vec[i].se.fi;
if(MN > pre && pre >= 0) chmax(dp[id][j], dp[id ^ 1][pre] + vec[i].se.se);
}
id ^= 1;
}
ll ans = 0;
for(int j = 0; j < MN; j++) chmax(ans, dp[id ^ 1][j]);
cout << ans << '\n';
}
# | 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... |