| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 991888 | crafticat | Cloud Computing (CEOI18_clo) | C++17 | 510 ms | 2680 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using tup = tuple<ll,ll,ll>;
ll n, q;
ll MAX_SUM = 0;
constexpr ll inf = 1e18;
vector<ll> solve(vector<tup> &data, bool mex) {
vector<ll> dp(vector<ll>(MAX_SUM + 1,mex ? 0 : inf));
dp[0] = 0;
for (ll i = 1; i <= data.size() ; ++i) {
vector<ll> newDp = dp;
auto [c, f, v] = data[i - 1];
for (ll j = 0; j <= MAX_SUM; ++j) {
if (mex) {
if (j - c >= 0) newDp[j] = max(dp[j],dp[j - c] + v);
} else {
if (j - c >= 0) newDp[j] = min(dp[j],dp[j - c] + v);
}
}
dp = newDp;
}
return dp;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(nullptr);
cin >> n;
vector<tup> arr(n);
ll s1 = 0, s2 = 0;
for (ll i = 0; i < n; ++i) {
ll c, f, v; cin >> c >> f >> v;
arr[i] = {c,f,v};
s1 += c;
}
cin >> q;
vector<tup> sell(q);
for (ll i = 0; i < q; ++i) {
ll c, f, v; cin >> c >> f >> v;
sell[i] = {c,f,v};
s2 += c;
}
MAX_SUM = max(s2, s1);
auto c = solve(arr,false), p = solve(sell,true);
ll ans = 0;
for (ll i = 0; i <= MAX_SUM; ++i) {
ans = max(ans, p[i] - c[i]);
}
cout << ans << "\n";
return 0;
}
Compilation message (stderr)
| # | 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... | ||||
