이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 MX = 4e3 + 10;
const int MN = 1e3 + 10;
const ll INF = 1e18;
int N, M;
ll dp[MX][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;
for(int i = 0; i < sz; i++){
for(int j = 0; j < MN; j++){
dp[i + 1][j] = dp[i][j];
int pre = j - vec[i].se.fi;
if(MN > pre && pre >= 0) chmax(dp[i + 1][j], dp[i][pre] + vec[i].se.se);
}
}
ll ans = 0;
for(int j = 0; j < MN; j++) chmax(ans, dp[sz][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... |