# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
153944 | karma | Cloud Computing (CEOI18_clo) | C++14 | 425 ms | 1528 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>
#define pb emplace_back
#define ll long long
using namespace std;
const int N = int(2e3) + 7;
const int M = N * 55;
const ll oo = (ll)1e18;
struct TComp{
int c, f, v;
bool type;
bool operator<(const TComp& o)const& {
return f > o.f || (f == o.f && type < o.type);
}
};
vector<TComp> v;
ll f[M], res = 0;
int n, m;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
if(fopen("test.inp", "r")) {
freopen("test.inp", "r", stdin);
freopen("test.out", "w", stdout);
}
cin >> n; v.resize(n);
for(int i = 0; i < n; ++i) {
cin >> v[i].c >> v[i].f >> v[i].v;
v[i].v *= -1, v[i].type = 0;
}
cin >> m; m += n; v.resize(m);
for(int i = n; i < m; ++i) {
cin >> v[i].c >> v[i].f >> v[i].v;
v[i].c *= -1, v[i].type = 1;
}
fill(f, f + M, -oo);
f[0] = 0;
sort(v.begin(), v.end());
for(TComp& comp: v) {
if(comp.c > 0) {
for(int i = int(1e5); i >= comp.c; --i)
f[i] = max(f[i - comp.c] + comp.v, f[i]);
} else {
for(int i = 0, lim = int(1e5) + comp.c; i <= lim; ++i)
f[i] = max(f[i - comp.c] + comp.v, f[i]);
}
}
for(int i = 0; i < M; ++i) res = max(res, f[i]);
cout << res;
}
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... |