Submission #783870

#TimeUsernameProblemLanguageResultExecution timeMemory
783870nononoCloud Computing (CEOI18_clo)C++14
100 / 100
274 ms1328 KiB
#include <bits/stdc++.h>
#define int long long
using namespace std;

struct cpt {
    int c, f, v;
    
    bool operator < (const cpt &x) const {
        return f > x.f;
    }
};

const int inf = 1e18;
const int mxN = 2005;
const int mxC = 50;

int n, m;
int dp[mxN * mxC];

signed main() {
    #define name ""

    if(fopen(name".in", "r")) {
        freopen(name".in", "r", stdin);
        freopen(name".out", "w", stdout);
    }

    cin.tie(0)->sync_with_stdio(0);
    
    cin >> n;
    
    vector<cpt> a, b; 
    
    for(int i = 1; i <= n; i ++) {
        int c, f, v;
        cin >> c >> f >> v;
        
        a.push_back({c, f, v});
    }
    
    sort(a.begin(), a.end());
    
    cin >> m;
    
    for(int i = 1; i <= m; i ++) {
        int c, f, v;
        cin >> c >> f >> v;
        
        b.push_back({c, f, v});
    }
    
    sort(b.begin(), b.end());
    
    for(int i = 0; i <= n * mxC; i ++) dp[i] = inf;
    
    int sumC = 0;
    dp[0] = 0;
    
    for(int i = 0, j = 0; i < m; i ++) {
        for(; j < n && a[j].f >= b[i].f; j ++) {
            sumC += a[j].c;
            
            for(int k = sumC; k >= a[j].c; k --) {
                dp[k] = min(dp[k], dp[k - a[j].c] + a[j].v); 
            }
        } 
        
        for(int k = b[i].c; k <= sumC; k ++) {
            dp[k - b[i].c] = min(dp[k - b[i].c], dp[k] - b[i].v);
        }
    }
    
    int result = 0;
    for(int i = 0; i <= sumC; i ++) result = max(result, - dp[i]);
    
    cout << result << "\n";
    return 0;
}

Compilation message (stderr)

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