이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll LINF = (ll) 1e18;
const int maxc = 10003;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n; cin >> n;
vector< tuple<int, int, int> > a;
int sum_c = 0;
for (int i = 0; i < n; i++) {
int c, f, v;
cin >> c >> f >> v;
sum_c += c;
a.emplace_back(f, v, c);
}
int m; cin >> m;
for (int i = 0; i < m; i++) {
int c, f, v;
cin >> c >> f >> v;
a.emplace_back(f, -v, c);
}
sort(a.rbegin(), a.rend());
vector< vector<ll> > dp(2, vector<ll>(sum_c + 1, -LINF));
dp[0][0] = 0;
for (int i = 0; i < n + m; i++) {
int cur = i % 2;
int f, v, c;
tie(f, v, c) = a[i];
for (int j = 0; j <= sum_c; j++) dp[!cur][j] = dp[cur][j];
if (v > 0) for (int j = 0; j + c <= sum_c; j++) dp[!cur][j + c] = max(dp[!cur][j + c], dp[cur][j] - v);
else for (int j = c; j <= sum_c; j++) dp[!cur][j - c] = max(dp[!cur][j - c], dp[cur][j] - v);
}
cout << *max_element(dp[(n + m) % 2].begin(), dp[(n + m) % 2].end()) << '\n';
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... |