이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define per(i, a, b) for (int i = b - 1; i >= (a); --i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define pb push_back
#define umap unordered_map
#define uset unordered_set
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef long long ll;
const int INF = 1000000007;
int main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
int n, m, c;
vector<pair<ii, pair<ll, int>>> dpvec;
ll f, v, sumc = 1, ans = 0;
cin >> n;
rep(i, 0, n) {
cin >> c >> f >> v;
dpvec.push_back({{f, 1}, {v, c}});
sumc += c;
}
cin >> m;
rep(i, 0, m) {
cin >> c >> f >> v;
dpvec.push_back({{f, 0}, {v, c}});
}
sort(all(dpvec), greater<>());
vector<ll> dp(sumc, -1e15), dp2 = dp;
dp[0] = 0;
bitset<100002> reach1, reach2;
reach1[0]=reach2[0] = 1;
trav(item, dpvec) {
int query;
tie(f, query) = item.first;
tie(v, c) = item.second;
int i = reach1._Find_first();
while(i!=100002){
ll cost = dp[i];
if (cost == -1e15) continue;
dp2[i] = max(dp2[i], cost);
if (query)
dp2[i + c] = max(dp2[i + c], cost - v),reach2.set(i+c);
else if (!query && c <= i)
dp2[i - c] = max(dp2[i - c], cost + v),reach2.set(i-c);;
i=reach1._Find_next(i);
}
reach1|=reach2;
dp.swap(dp2);
dp2.assign(sumc, -1e15);
}
trav(val, dp) ans = max(ans, val);
cout << ans << endl;
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... |