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;
using ll = long long;
#define pb push_back
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()
#define f first
#define s second
#define mkp make_pair
#define pii pair<int, int>
bool ckmin(ll& a, ll b){ return b < a ? a = b, true : false; }
bool ckmax(ll& a, ll b){ return b > a ? a = b, true : false; }
struct C{
int c, r;
ll p;
};
const int N = 4000;
int n, m, sc;
C v[N];
ll dp[2][N * 50];
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n;
for(int i = 0; i < n; i++){
cin >> v[i].c >> v[i].r >> v[i].p;
v[i].p = -v[i].p;
sc += v[i].c;
}
cin >> m;
for(int i = n; i < n + m; i++){
cin >> v[i].c >> v[i].r >> v[i].p;
v[i].c = -v[i].c;
}
sort(v, v + n + m, [](C &c1, C &c2){
if(c1.r != c2.r) return c1.r > c2.r;
return c1.c > c2.c;
});
fill(dp[0] + 1, dp[0] + sc + 1, -1e18);
fill(dp[1] + 1, dp[1] + sc + 1, -1e18);
for(int i = 0; i < n + m; i++){
for(int j = 0; j <= sc; j++){
if(0 <= j + v[i].c && j + v[i].c <= sc){
ckmax(dp[1][j + v[i].c], dp[0][j] + v[i].p);
}
}
for(int j = 0; j <= sc; j++){
dp[0][j] = dp[1][j];
}
}
cout << *max_element(dp[0], dp[0] + sc + 1) << '\n';
return 0;
}
# | 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... |