# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
335393 | parsabahrami | Cloud Computing (CEOI18_clo) | C++17 | 306 ms | 8428 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;
typedef long long int ll;
typedef pair<int, int> pii;
#define SZ(x) (int) x.size()
#define F first
#define S second
const int N = 1e6 + 10, MOD = 1e9 + 7;
ll n, m, k, dp[N], sum = 0; pair<int, pii> A[N];
int main() {
scanf("%lld", &n);
for (int i = 1; i <= n; i++) {
int c, f, v; scanf("%d%d%d", &c, &f, &v);
A[i] = {f, {c, v}};
}
scanf("%lld", &m);
for (int i = 1; i <= m; i++) {
int c, f, v; scanf("%d%d%d", &c, &f, &v);
A[i + n] = {f, {-c, v}};
}
sort(A + 1, A + n + m + 1);
fill(dp + 1, dp + N, -1e18);
for (int i = n + m; i >= 1; i--) {
pii X = A[i].S; int c = abs(X.F), v = X.S;
if (X.F > 0) {
for (int j = sum; j >= 0; j--) {
dp[j + c] = max(dp[j + c], dp[j] - v);
}
sum += c;
} else {
for (int j = c; j <= sum; j++) {
dp[j - c] = max(dp[j - c], dp[j] + v);
}
}
}
printf("%lld\n", *max_element(dp, dp + 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... |