Submission #752839

#TimeUsernameProblemLanguageResultExecution timeMemory
752839nguyenneheheCloud Computing (CEOI18_clo)C++14
72 / 100
499 ms1868 KiB
#include<bits/stdc++.h>
using namespace std;

signed main() {
  cin.tie(nullptr)->sync_with_stdio(false);

  int n; cin >> n;
  vector<array<int, 3>> a;
  int sumc = 0;
  for (int i = 0; i < n; ++i) {
    int c, f, v; cin >> c >> f >> v;
    a.push_back({c, f, -v});

    sumc += c;
  }
  int m; cin >> m;
  for (int i = 0; i < m; ++i) {
    int c, f, v; cin >> c >> f >> v;
    a.push_back({-c, f, v});
  }

  sort(a.begin(), a.end(), [](array<int, 3> x, array<int, 3> y) {
    return x[1] > y[1];
  });

  const long long INF = 2e18;
  vector<long long> dp(sumc + 1, -INF);
  dp[0] = 0;
  for (auto [c, f, v]: a) {
    vector<long long> cur = dp;
    for (int w = 0; w <= sumc; ++w) {
      int req = w - c;
      if (req < 0 || req > sumc) continue;
      if (dp[req] == -INF) continue;
      cur[w] = max(cur[w], dp[req] + v);
    }

    swap(dp, cur);
  }

  cout << *max_element(dp.begin(), dp.end());
}

Compilation message (stderr)

clo.cpp: In function 'int main()':
clo.cpp:29:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   29 |   for (auto [c, f, v]: a) {
      |             ^
#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...