이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define X first
#define Y second
#define pii pair<int,int>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
void abc() {cout << endl;}
template <typename T, typename ...U> void abc(T i, U ...j) {
cout << i << ' ', abc(j...);
}
template <typename T> void printv(T l, T r) {
for (; l != r; ++l)
cout << *l << " \n"[l + 1 == r];
}
#ifdef Doludu
#define test(x...) abc("[" + string(#x) + "]", x);
#define owo freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#else
#define test(x...) void(0);
#define owo ios::sync_with_stdio(false), cin.tie(0)
#endif
const int N = 200000;
struct item {
int c, f, v, ty;
bool operator < (const item &o) {
if (f == o.f)
return ty < o.ty;
return f > o.f;
}
};
int main () {
owo;
int n, m;
vector <item> a;
cin >> n;
for (int i = 0, c, f, v; i < n; ++i)
cin >> c >> f >> v, a.pb({c, f, v, 0});
cin >> m;
for (int i = 0, c, f, v; i < m; ++i)
cin >> c >> f >> v, a.pb({c, f, v, 1});
sort(all(a));
int S = n * 50 + 1;
vector <lli> dp(S, -1ll << 60);
dp[0] = 0;
for (int i = 0; i < n + m; ++i) {
if (a[i].ty) {
for (int j = 0; j < S - a[i].c; ++j) {
dp[j] = max(dp[j], dp[j + a[i].c] + a[i].v);
}
} else {
for (int j = S - a[i].c - 1; ~j; --j) {
dp[j + a[i].c] = max(dp[j + a[i].c], dp[j] - a[i].v);
}
}
}
cout << *max_element(all(dp)) << endl;
}
# | 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... |