이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define piii pair<int,pair<int,int>>
#define fi first
#define se second
const int N = 2e3 + 5;
const int inf = 0x3f3f3f3f3f3f3f3f;
vector<piii>vec;
vector<int>dp_before(105,-inf),dp_cur(105,-inf);
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
int c,f,v;
cin >> c >> f >> v;
vec.push_back({f,{c,-v}});
}
int m;
cin >> m;
for (int i = 1; i <= m; i++) {
int c,f,v;
cin >> c >> f >> v;
vec.push_back({f,{-c,v}});
}
sort(vec.begin(),vec.end(),greater<piii>());
dp_before[0] = 0;
for (int i = 0; i < (int)vec.size(); i++) {
dp_cur = dp_before;
for (int j = 0; j <= 50; j++) {
if (dp_before[j] == -inf) continue;
int newCnt = j + vec[i].se.fi,newCost = dp_before[j] + vec[i].se.se;
if (newCnt >= 0) dp_cur[newCnt] = max(dp_cur[newCnt],newCost);
}
dp_before = dp_cur;
}
int ans = 0;
for (auto x: dp_before) ans = max(ans,x);
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... |