Submission #888372

#TimeUsernameProblemLanguageResultExecution timeMemory
888372NoLoveCloud Computing (CEOI18_clo)C++14
100 / 100
391 ms1372 KiB
/**
 *    author : Lăng Trọng Đạt
 *    created: 17-12-2023 
**/
#include <bits/stdc++.h>
using namespace std;
#ifndef LANG_DAT
#define db(...) ;
#endif // LANG_DAT
#define int int64_t
#define mp make_pair
#define f first
#define s second
#define pb push_back
#define all(v) (v).begin(), (v).end()
using pii = pair<int, int>;

const int INF = 1e15;
vector<int> dp; // dp[i][j]: maximum profit of first i "transaction" and j cores left
vector<vector<int>> g; // {f, c, v}
int n, m, cores_cnt = 0;

int32_t main() {
    cin.tie(0)->sync_with_stdio(0);
    if (fopen("hi.inp", "r")) {
        freopen("hi.inp", "r", stdin);
//        freopen("hi.out", "w", stdout);
    } 

    cin >> n;
    for (int i = 0, c, f, v; i < n; i++) {
        cin >> c >> f >> v;
        cores_cnt += c;
        g.pb({f, c, -v});
    }
    cin >> m;
    for (int i = 0, c, f, v; i < m; i++) {
        cin >> c >> f >> v;
        g.pb({f, -c, v});
    }
    sort(all(g), greater<vector<int>>());
    int res = 0;
    dp.assign(cores_cnt + 5, -INF);
    dp[0] = 0;
    for (auto x : g) {
        if (x[1] < 0) {
            // db(i - x[1] - cores_cnt)
            for (int i = 0; i - x[1] <= cores_cnt; i++) {
                dp[i] = max(dp[i], dp[i - x[1]] + x[2]);
            }
        } else {
            for (int i = cores_cnt; i >= x[1]; i--) {
                dp[i] = max(dp[i], dp[i - x[1]] + x[2]);
            }
        }
        // } else {
        //     for (int i = )
        // }
    }
    cout << *max_element(all(dp));
}

Compilation message (stderr)

clo.cpp: In function 'int32_t main()':
clo.cpp:42:9: warning: unused variable 'res' [-Wunused-variable]
   42 |     int res = 0;
      |         ^~~
clo.cpp:26:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         freopen("hi.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#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...