Submission #788265

#TimeUsernameProblemLanguageResultExecution timeMemory
788265TS_2392Cloud Computing (CEOI18_clo)C++14
72 / 100
204 ms1804 KiB
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
// using namespace __gnu_pbds;

#define fileIO(name)  if(fopen(name".inp", "r")) {freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout);}
#define SPEED         ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define EL            cout << '\n'
#define dbg(x)        cout << #x << " = " << (x) << ' '
#define dbgp(x)       cout << #x << " = (" << (x.fi) << ", " << (x.se) << ") "
#define dbga(x, l, r) {cout << #x << '[' << l << ", " << r << "] = { "; for(int i = l; i <= (int)r; ++i) cout << x[i] << ' '; cout << "} ";}

#define epl           emplace
#define pb            push_back
#define eb            emplace_back
#define fi            first
#define se            second
#define mp            make_pair

#define sqr(x)        ((x) * (x))
#define all(x)        (x).begin(), (x).end()
#define rall(x)       (x).rbegin(), (x).rend()
#define lwb           lower_bound
#define upb           upper_bound
#define ctz           __builtin_ctzll // or __builtin_ctz
#define pct           __builtin_popcountll // or __builtin_popcount

typedef long long            ll;
typedef long double          ldb;
typedef unsigned int         uint;
typedef unsigned long long   ull;
typedef pair<ll, ll>         pll;
typedef pair<ll, int>        pli;
typedef pair<int, ll>        pil;
typedef pair<int, int>       pii;
typedef pair<ldb, ldb>       pld;
typedef pair<double, double> pdd;

template<class T1, class T2> bool minimize(T1 &a, T2 b){return a > b ? a = b, true : false;}
template<class T1, class T2> bool maximize(T1 &a, T2 b){return a < b ? a = b, true : false;}

// int d4x[4] = {1, 0, -1, 0}, d8x[8] = {0, 1, 1, 1, 0, -1, -1, -1};
// int d4y[4] = {0, 1, 0, -1}, d8y[8] = {1, 1, 0, -1, -1, -1, 0, 1};

// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;
const int N = 2002;
const ll oo = 1e18;
struct Items{
    int c, f;
    ll v;
    bool operator < (const Items &oth) const{
        return f > oth.f || (f == oth.f && c > oth.c);
    }
} item[N * 2];
int n, m, sz;
void TS_2392(){
    cin >> n;
    for(int i = 1; i <= n; ++i){
        cin >> item[i].c >> item[i].f >> item[i].v;
        item[i].v = -item[i].v;
    }
    cin >> m;
    for(int i = n + 1; i <= n + m; ++i){
        cin >> item[i].c >> item[i].f >> item[i].v;
        item[i].c = -item[i].c;
    }
    sz = n + m;
    sort(item + 1, item + 1 + sz);
    vector<ll> dp(1);
    for(int i = 0; i < sz; ++i){
        if(item[i + 1].c > 0){
            dp.resize((int)dp.size() + item[i + 1].c, -oo);
            for(int d = dp.size() - 1; d >= 0; --d){
                maximize(dp[d + item[i + 1].c], dp[d] + item[i + 1].v);
            }
        }
        else{
            for(int d = -item[i + 1].c; d < dp.size(); ++d){
                maximize(dp[d + item[i + 1].c], dp[d] + item[i + 1].v);
            }
        }
    }
    cout << *max_element(dp.begin(), dp.end());
}
int main(){
    SPEED; fileIO("text");
    int numtest = 1; //cin >> numtest;
    for(int itest = 1; itest <= numtest; ++itest){
        // cout << "Case #" << itest << ": ";
        TS_2392();
    }
    return 0;
}

Compilation message (stderr)

clo.cpp: In function 'void TS_2392()':
clo.cpp:81:43: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |             for(int d = -item[i + 1].c; d < dp.size(); ++d){
      |                                         ~~^~~~~~~~~~~
clo.cpp: In function 'int main()':
clo.cpp:8:58: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 | #define fileIO(name)  if(fopen(name".inp", "r")) {freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout);}
      |                                                   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:89:12: note: in expansion of macro 'fileIO'
   89 |     SPEED; fileIO("text");
      |            ^~~~~~
clo.cpp:8:91: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 | #define fileIO(name)  if(fopen(name".inp", "r")) {freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout);}
      |                                                                                    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:89:12: note: in expansion of macro 'fileIO'
   89 |     SPEED; fileIO("text");
      |            ^~~~~~
#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...