이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 2e3 + 2;
const int M = 51 * N;
const ll linf = 9e18;
ll dp[2][M];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
vector<array<int, 4>> all;
int n; cin >> n;
for (int i = 0; i < n; i++) {
int a, b, c;
cin >> a >> b >> c;
all.push_back({a, b, c, 0});
}
int m; cin >> m;
for (int i = 0; i < m; i++) {
int a, b, c;
cin >> a >> b >> c;
all.push_back({a, b, c, 1});
}
sort(all.begin(), all.end(), [&] (array<int, 4> i, array<int, 4> j) {
if (i[1] != j[1]) return i[1] > j[1];
return i[3] < j[3];
});
for (int i = 0; i < 2; i++) for (int j = 0; j < M; j++) dp[i][j] = -linf;
dp[0][0] = 0;
int ii = 0;
for (auto u : all) {
ii ^= 1;
for (int j = 0; j < M; j++) dp[ii][j] = dp[1 - ii][j];
if (u[3] == 0) {
for (int j = u[0]; j < M; j++) if (dp[1 - ii][j - u[0]] != -linf) smax(dp[ii][j], dp[1 - ii][j - u[0]] - u[2]);
}
else {
for (int j = u[0]; j < M; j++) if (dp[1 - ii][j] != -linf) smax(dp[ii][j - u[0]], dp[1 - ii][j] + u[2]);
}
}
ll ans = -linf;
for (int j = 0; j < M; j++) smax(ans, dp[ii][j]);
cout << ans << en;
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... |