이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// Success consists of going from failure to failure without loss of enthusiasm
#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
#define pb push_back
using ll = long long;
template<class T> using V = vector<T>;
using vi = V<int>;
using vl = V<ll>;
const int nax = int(1e5) + 5;
ll dp[nax];
V<array<int, 4>> A;
int main() {
cin.tie(0)->sync_with_stdio(0);
int N; cin >> N;
for(int i = 0; i < N; i++) {
int c, f, v; cin >> c >> f >> v;
A.pb(array<int, 4>{f, 1, c, v});
}
int M; cin >> M;
for(int i = 0; i < M; i++) {
int c, f, v; cin >> c >> f >> v;
A.pb(array<int, 4>{f, -1, c, v});
}
sort(begin(A), end(A), [&](const array<int, 4> &a, const array<int, 4> &b) {
if (a[0] == b[0]) return a[1] < b[1];
else return a[0] < b[0];
});
memset(dp, -1, sizeof dp); dp[0] = 0;
int MX = 0;
for(int i = 0; i < N + M; i++) {
int c = A[i][2], v = A[i][3], y;
if (A[i][1] == -1) {
for(int x = MX; x >= 0; x--) if (dp[x] != -1) {
y = x + c;
if (y < nax) dp[y] = max(dp[x] + v, dp[y]);
}
MX += c;
} else {
for(int x = 0; x <= MX; x++) if (dp[x] != -1) {
if (x < c) y = 0;
else y = x - c;
dp[y] = max(dp[x] - v, dp[y]);
}
}
}
cout << dp[0] << nl;
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... |