이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// Success consists of going from failure to failure without loss of enthusiasm
#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>;
int main() {
cin.tie(0)->sync_with_stdio(0);
int N; cin >> N;
V<pair<int, int>> A;
V<array<int, 2>> CS, CB;
for(int i = 0; i < N; i++) {
int c, f, v; cin >> c >> f >> v;
A.pb(make_pair(f, i));
CB.pb(array<int, 2>{c, v});
}
int M; cin >> M;
for(int i = 0; i < M; i++) {
int c, f, v; cin >> c >> f >> v;
A.pb(make_pair(f, i + N));
CS.pb(array<int, 2>{c, v});
}
sort(begin(A), end(A));
const int nax = N * 50 + 5;
ll dp[nax]; memset(dp, -1, sizeof dp);
dp[0] = 0;
V<array<int, 2>> S, B;
for(int i = 0; i < N + M; i++) {
S = B = {};
int j = i;
while(j < N + M && A[j].first == A[i].first) {
if (A[j].second >= N) S.pb(CS[A[j].second - N]);
else B.pb(CB[A[j].second]);
j++;
}
i = j - 1;
for(auto &s : S) {
int c = s[0], v = s[1];
for(int x = nax - 1; x >= 0; x--) if (dp[x] != -1) {
int y = x + c;
if (y < nax) dp[y] = max(dp[x] + v, dp[y]);
}
}
for(auto &s : B) {
int c = s[0], v = s[1];
for(int x = 0; x < nax; x++) if (dp[x] != -1) {
int y = max(x - int(c), 0);
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... |