Submission #518515

#TimeUsernameProblemLanguageResultExecution timeMemory
518515LptN21Cloud Computing (CEOI18_clo)C++14
100 / 100
415 ms1304 KiB
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL);
#define PI acos(-1.0)
#define eps 1e-9
#define FF first
#define SS second
// VECTOR (6)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sz(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define uniq(v) sort(all( (v) )), (v).resize( unique(all( (v) )) - (v).begin() );
// BIT (6)
#define CNTBIT(x) __builtin_popcountll(x)
#define ODDBIT(x) __builtin_parityll(x)
#define MASK(i) (1LL<<(i))
#define BIT(x, i) (((x)>>(i))&1)
#define SUBSET(big, small) (((big)&(small))==(small))
#define MINBIT(x) (x)&(-x)
//typedef
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, int> ii;
/* CODE BELOW */
const int N = 2e3 + 7, M = 50 + 7;
const ll oo = 1e16 + 7;
const int MOD = 1e9 + 7;

int n, m, k, t;

struct Product{
    int c, f, v; Product() {}
    Product(int _c, int _f, int _v):
        c(_c), f(_f), v(_v) {}
    bool operator<(const Product &o) const {
        if(f != o.f) return f < o.f;
        if(c != o.c) return c < o.c;
        return o.v < o.v;
    }
} a[N], b[N];

ll _dp[N * M];

signed main() {
    //freopen("test.inp", "r", stdin);
    //freopen("test.out", "w", stdout);
    //fastIO;
    scanf("%d", &n);
    int c, f, v;
    for(int i=1;i<=n;i++) {
        scanf("%d%d%d", &c, &f, &v);
        a[i] = Product(c, f, v);
    }
    scanf("%d", &m);
    for(int i=1;i<=m;i++) {
        scanf("%d%d%d", &c, &f, &v);
        b[i] = Product(c, f, v);
    }
    sort(a+1, a+n+1), sort(b+1, b+m+1);
    for(int i=1;i<N*M;i++) _dp[i] = -oo;

    for(int j=n, i=m;i>0;i--) {
        for(;j>0&&a[j].f>=b[i].f;j--) {
            for(int k=N*M-1;k>=a[j].c;k--) {
                _dp[k] = max(_dp[k], _dp[k - a[j].c] - a[j].v);
            }
        }
        for(int k=0;k+b[i].c<N*M;k++) {
            _dp[k] = max(_dp[k], _dp[k + b[i].c] + b[i].v);
        }
    }

    ll ans = 0;
    for(int i=0;i<N*M;i++) ans = max(ans, _dp[i]);
    printf("%lld", ans);

    return 0;
}

Compilation message (stderr)

clo.cpp: In member function 'bool Product::operator<(const Product&) const':
clo.cpp:41:20: warning: self-comparison always evaluates to false [-Wtautological-compare]
   41 |         return o.v < o.v;
      |                ~~~ ^ ~~~
clo.cpp: In function 'int main()':
clo.cpp:51:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
clo.cpp:54:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |         scanf("%d%d%d", &c, &f, &v);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
clo.cpp:57:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |     scanf("%d", &m);
      |     ~~~~~^~~~~~~~~~
clo.cpp:59:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |         scanf("%d%d%d", &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...