Submission #1258587

#TimeUsernameProblemLanguageResultExecution timeMemory
1258587bnd2100Cloud Computing (CEOI18_clo)C++20
100 / 100
166 ms2132 KiB
/*
* @Author: Twynzz
* @Last Modified by: Twynzz
* @Note For This Problem: https://wbd.ms/share/v2/aHR0cHM6Ly93aGl0ZWJvYXJkLm1pY3Jvc29mdC5jb20vYXBpL3YxLjAvd2hpdGVib2FyZHMvcmVkZWVtLzVhZWY2Y2M0YWM0YjRkODFiYTJjODJlZjk3ZDQzYTg3X0JCQTcxNzYyLTEyRTAtNDJFMS1CMzI0LTVCMTMxRjQyNEUzRF85MmM3ZTI1Yi00N2Y0LTQzMTAtOWI3Yy02ZmVjMjkxYTMzMTU=
*/


#include <bits/stdc++.h>
using namespace std;

// ------------ Define ------------

#define el "\n"
#define int long long
#define ld long double
#define str string
#define file(name) {freopen(name".inp","r",stdin);freopen(name".out","w",stdout);}
#define IOS {std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
#define _TBN_ signed main()
#define setp(n) setprecision(n)<< fixed
#define fi first
#define se second
#define ii pair<int,int>
#define gcd(a,b) __gcd(a,b)
#define tup pair<int,ii>
#define pb push_back
#define pf push_front
#define eb emplace_back
#define sz(v) (int)v.size()

const int maxn = 2e5+9;
const long long oo = 1e18;
const int MOD = 1e9+7, Mod = 998244353;
const int base = 311;

template<class X>
    bool maximize(X &a, const X &b)
    {
        if (a<b)
        {
            a = b;
            return 1;
        }
        return 0;
    }

template<class X>
    bool minimize(X &a, const X &b)
    {
        if (a>b)
        {
            a = b;
            return 1;
        }
        return 0;
    }

namespace sub1
{
    bool checkSub1();
    void sub1();
}
namespace sub2
{
    bool checkSub2();
    void sub2();
}
namespace sub3
{
    bool checkSub3();
    void sub3();
}

int lcm(int a, int b)
{
    return a/gcd(a,b)*b;
}

int sqr(int x) {return x*x;}

inline bool MASK(int mask, int bit) {return ((mask>>bit)&1);}
inline long long F(int n) {return n*(n+1)/2;}
inline int add(int a, int b, int m = MOD) {return ((a%m+b%m)%m+m)%m;}
inline int sub(int a, int b, int m = MOD) {return ((a-b)%m+m)%m;}
inline int mul(int a, int b, int m = MOD) {return ((a%m)*(b%m))%m;}

int dx[] = {-1, 0, 1};
int dy[] = {1, 1, 1};

// ------------ Code ------------

struct cp
{
    int c, f, v, id;
};

bool cmp(cp a, cp b)
{
    if (a.f == b.f) return a.id < b.id;
    return a.f > b.f;
}

int n, m;
cp a[5009];
_TBN_
{
    IOS;
    if (fopen("CLOUD.inp","r")) file("CLOUD");
    cin >>n;
    for(int i = 1; i <= n; i++)
    {
        cin >>a[i].c >>a[i].f >>a[i].v;
        a[i].id = i;
    }
    cin >>m;
    for(int i = 1; i <= m; i++)
    {
        cin >>a[n + i].c >>a[n + i].f >>a[n + i].v;
        a[n + i].id = n + i;
    }
    for(int i = 1; i <= 1; i++)
    {
        if (sub1::checkSub1()) {sub1::sub1(); return 0;}
        // if (sub2::checkSub2()) {sub2::sub2(); return 0;}
        // if (sub3::checkSub3()) {sub3::sub3(); return 0;}
    }
    return 0;
}

namespace sub1
{
    bool checkSub1()
    {
        return 1;
    }
    int dp[maxn];
    void sub1()
    {
        int sum = 0;
        sort(a + 1, a + 1 + n + m, cmp);
        for(int i = 0; i < maxn; i++) dp[i] = -oo;
        dp[0] = 0;
        for(int i = 1; i <= n + m; i++)
        {
            if (a[i].id <= n)
            {
                for(int j = sum; j >= 0; j--)
                    maximize(dp[j + a[i].c], dp[j] - a[i].v);
                sum += a[i].c;
            }
            else
            {
                for(int j = a[i].c; j <= sum; j++)
                    maximize(dp[j - a[i].c], dp[j] + a[i].v);
            }
        }
        cout<< *max_element(dp, dp + maxn)<< el;
    }
}
 




Compilation message (stderr)

clo.cpp: In function 'int main()':
clo.cpp:17:28: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 | #define file(name) {freopen(name".inp","r",stdin);freopen(name".out","w",stdout);}
      |                     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
clo.cpp:108:33: note: in expansion of macro 'file'
  108 |     if (fopen("CLOUD.inp","r")) file("CLOUD");
      |                                 ^~~~
clo.cpp:17:58: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 | #define file(name) {freopen(name".inp","r",stdin);freopen(name".out","w",stdout);}
      |                                                   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:108:33: note: in expansion of macro 'file'
  108 |     if (fopen("CLOUD.inp","r")) file("CLOUD");
      |                                 ^~~~
#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...