# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
148091 | WhipppedCream | Cloud Computing (CEOI18_clo) | C++17 | 396 ms | 1400 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;
#define X first
#define Y second
#define pb push_back
typedef pair<int, int> ii;
typedef long long ll;
const int lim = 1e5+5;
ll dp[lim];
struct node
{
int c, v, f, t;
node(int _c, int _v, int _f, int _t)
{
c = _c; v = _v; f = _f; t = _t;
}
bool operator < (node other) const
{
if(f != other.f) return f> other.f;
return t< other.t;
}
};
vector<node> items;
int n, m;
int main()
{
scanf("%d", &n);
for(int i = 1; i<= n; i++)
{
int c, v, f; scanf("%d %d %d", &c, &f, &v);
items.pb(node(c, v, f, -1));
}
scanf("%d", &m);
for(int i = 1; i<= m; i++)
{
int c, v, f; scanf("%d %d %d", &c, &f, &v);
items.pb(node(c, v, f, 1));
}
sort(items.begin(), items.end());
for(int i = 1; i<= 1e5; i++) dp[i] = -1e15;
dp[0] = 0;
for(auto pong : items)
{
int w = -pong.c*pong.t;
int v = pong.v*pong.t;
//printf("%d %d\n", w, v);
if(w> 0)
{
//buy
for(int i = 1e5; i>= w; i--)
{
dp[i] = max(dp[i], v+dp[i-w]);
}
}
else
{
//sell
for(int i = 0; i<= ((int)1e5+w); i++)
{
dp[i] = max(dp[i], v+dp[i-w]);
}
}
//printf("dp[1] = %lld\n", dp[1]);
}
ll best = 0;
for(int i = 0; i<= 1e5; i++) best = max(best, dp[i]);
printf("%lld\n", best);
//for(int i = 0; i<= 1e5; i++) if(dp[i] == best) printf("%d\n", i);
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... |