이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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++){
ckmax(dp[1][j], dp[0][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];
dp[1][j] = -1e18;
}
}
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... |