이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct NODE {
ll w;
ll f;
ll v;
bool operator<(const NODE& b) {
if (this->f == b.f) return this->w > b.w;
return this->f > b.f;
}
};
const ll MAXW = 4000 * 50 + 100;
void solve() {
ll N, M;
vector<NODE> a;
cin >> N;
for (int i = 0; i < N; i++) {
ll c, f, v;
cin >> c >> f >> v;
a.push_back({c, f, -v});
}
cin >> M;
for (int i = 0; i < M; i++) {
ll c, f, v;
cin >> c >> f >> v;
a.push_back({-c, f, v});
}
sort(a.begin(), a.end());
//for (auto x : a) cout << x.w << " " << x.v << endl;
ll n = a.size();
ll dp[2][MAXW];
for (int i = 0; i < MAXW; i++) dp[0][i] = -1e18;
dp[0][0] = 0;
for (int i = 1; i <= n; i++) {
ll v = a[i-1].v;
ll w = a[i-1].w;
int cur = i%2;
int prev = !cur;
for (int j = MAXW-1; j >= 0; j--) {
dp[cur][j] = dp[prev][j];
if (j - w >= 0 && j - w < MAXW && dp[prev][j - w] != -1e18) dp[cur][j] = max(dp[cur][j], dp[prev][j - w] + v);
}
}
ll ans = 0;
for (int i = 0; i < MAXW; i++) ans = max(ans, dp[n%2][i]);//cout << x << " "; cout << endl;
cout << ans << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int t = 1;
//cin >> t;
while (t--) solve();
}
# | 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... |