Submission #1112012

#TimeUsernameProblemLanguageResultExecution timeMemory
1112012KALARRYCloud Computing (CEOI18_clo)C++14
36 / 100
7 ms1104 KiB
//chockolateman

#include<bits/stdc++.h>

using namespace std;

const long long INF = 1e15;

long long N,M,dp[2][10005];

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)

clo.cpp: In function 'int main()':
clo.cpp:22:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |     scanf("%lld",&N);
      |     ~~~~~^~~~~~~~~~~
clo.cpp:26:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         scanf("%lld%lld%lld",&c,&f,&v);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:30:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |     scanf("%lld",&M);
      |     ~~~~~^~~~~~~~~~~
clo.cpp:33:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |         scanf("%lld%lld%lld",&c,&f,&v);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...