# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1112014 | KALARRY | Cloud Computing (CEOI18_clo) | C++14 | 388 ms | 2208 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.
//chockolateman
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e15;
long long N,M,dp[2][100005];
struct Transact
{
long long type,c,f,v; // type is 1 for buying and 0 for selling
bool operator < (const Transact &Other)
{
return make_pair(f,type) > make_pair(Other.f,Other.type);
}
} transactions[4005];
int main()
{
scanf("%lld",&N);
long long total = 0;
for(long long c,f,v,i = 1 ; i <= N ; i++)
{
scanf("%lld%lld%lld",&c,&f,&v);
transactions[i] = {1,c,f,v};
total += c;
}
scanf("%lld",&M);
for(long long c,f,v,i = 1 ; i <= M ; i++)
{
scanf("%lld%lld%lld",&c,&f,&v);
transactions[N+i] = {0,c,f,v};
}
sort(transactions+1,transactions+N+M+1);
for(int j = 1 ; j <= total ; j++)
dp[0][j] = - INF;
for(int i = 1 ; i <= N+M ; i++)
{
for(int j = 0 ; j <= total ; j++)
{
dp[i%2][j] = dp[(i-1)%2][j];
long long type = transactions[i].type;
long long c = transactions[i].c;
// long long f = transactions[i].f;
long long v = transactions[i].v;
if(type==1 && j >= c)
dp[i%2][j] = max(dp[i%2][j],dp[(i-1)%2][j - c] - v);
else if(type==0 && j + c <= total)
dp[i%2][j] = max(dp[i%2][j],dp[(i-1)%2][j + c] + v);
}
}
long long ans = 0;
for(int j = 0 ; j <= total ; j++)
ans = max(ans,dp[(N+M)%2][j]);
printf("%lld\n",ans);
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... |