Submission #153945

#TimeUsernameProblemLanguageResultExecution timeMemory
153945karmaCloud Computing (CEOI18_clo)C++14
100 / 100
399 ms1416 KiB
#include<bits/stdc++.h>
#define pb      emplace_back
#define ll      long long

using namespace std;

const int N = int(2e3) + 7;
const int M = N * 55;
const ll oo = (ll)1e18;

struct TComp{
    int c, f, v;
    bool operator<(const TComp& o)const& {
        return f > o.f || (f == o.f && v < o.v);
    }
};
vector<TComp> v;
ll f[M], res = 0;
int n, m;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    if(fopen("test.inp", "r")) {
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    }
    cin >> n; v.resize(n);
    for(TComp& comp: v) {
       cin >> comp.c >> comp.f >> comp.v;
       comp.v *= -1;
    }
    cin >> m; m += n; v.resize(m);
    for(int i = n; i < m; ++i) {
       cin >> v[i].c >> v[i].f >> v[i].v;
       v[i].c *= -1;
    }
    fill(f, f + M, -oo);
    f[0] = 0;
    sort(v.begin(), v.end());
    for(TComp& comp: v) {
       if(comp.c > 0) {
          for(int i = int(1e5); i >= comp.c; --i)
             f[i] = max(f[i - comp.c] + comp.v, f[i]);
       } else {
          for(int i = 0, lim = int(1e5) + comp.c; i <= lim; ++i)
             f[i] = max(f[i - comp.c] + comp.v, f[i]);
       }
    }
    for(int i = 0; i < int(1e5); ++i) res = max(res, f[i]);
    cout << res;
}

Compilation message (stderr)

clo.cpp: In function 'int main()':
clo.cpp:25:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen("test.inp", "r", stdin);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:26:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen("test.out", "w", stdout);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...