Submission #307023

#TimeUsernameProblemLanguageResultExecution timeMemory
307023VROOM_VARUNCloud Computing (CEOI18_clo)C++14
18 / 100
586 ms1664 KiB
/*
ID: varunra2
LANG: C++
TASK: clo
*/
 
#include <bits/stdc++.h>
using namespace std;
 
#ifdef DEBUG
#include "lib/debug.h"
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define debug_arr(...) \
  cerr << "[" << #__VA_ARGS__ << "]:", debug_arr(__VA_ARGS__)
#pragma GCC diagnostic ignored "-Wsign-compare"
//#pragma GCC diagnostic ignored "-Wunused-parameter"
//#pragma GCC diagnostic ignored "-Wunused-variable"
#else
#define debug(...) 42
#endif
 
#define EPS 1e-9
#define IN(A, B, C) assert(B <= A && A <= C)
#define INF (int)1e9
#define MEM(a, b) memset(a, (b), sizeof(a))
#define MOD 1000000007
#define MP make_pair
#define PB push_back
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define x first
#define y second
#define int long long
 
const double PI = acos(-1.0);
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef map<int, int> MPII;
typedef multiset<int> MSETI;
typedef set<int> SETI;
typedef set<string> SETS;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef vector<string> VS;
 
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto& a : x)
#define sz(x) (int)(x).size()
typedef pair<int, int> pii;
typedef vector<int> vi;
#pragma GCC diagnostic ignored "-Wsign-compare"
// util functions
 
#define MXSUM 2000 * 50
 
void prvec(VVI& v, string s = "") {
  debug(s);
 
  for (int i = 0; i < sz(v); i++) {
    debug(i, v[i]);
  }
}
 
int32_t main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
 
  int n, m;
  cin >> n;
 
  VVI comps(n, VI(3));
 
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> comps[i][j];
    }
    // negative cost
    comps[i][2] *= -1;
    swap(comps[i][0], comps[i][1]);
  }
 
  cin >> m;
 
  VVI ords(m, VI(3));
 
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> ords[i][j];
    }
    swap(ords[i][0], ords[i][1]);
    // you lose cores
    ords[i][1] *= -1;
  }
 
  sort(all(comps));
  sort(all(ords));
  reverse(all(comps));
  reverse(all(ords));
 
  VVI vals;
 
  int p1 = 0, p2 = 0;
 
  while (p1 < n and p2 < m) {
    if (comps[p1] >= ords[p2]) {
      vals.PB(comps[p1]);
      p1++;
    } else {
      vals.PB(ords[p2]);
      p2++;
    }
  }
 
  while (p1 < n) {
    vals.PB(comps[p1]);
    p1++;
  }
  while (p2 < m) {
    vals.PB(ords[p2]);
    p2++;
  }
 
  VI dp(MXSUM + 1, -INF);
 
  dp[0] = 0ll;
 
  for (int i = 0; i < (int)vals.size(); i++) {
    if (vals[i][2] < 0) {
      for (int ii = MXSUM; ii >= vals[i][1]; ii--) {
        dp[ii] = max(dp[ii], dp[ii - vals[i][1]] + vals[i][2]);
      }
    } else {
      for (int ii = 0; ii <= MXSUM + vals[i][1]; ii++) {
        dp[ii] = max(dp[ii], dp[ii - vals[i][1]] + vals[i][2]);
      }
    }
  }
 
  cout << *max_element(all(dp)) << '\n';
  // prvec(vals);
  // prvec(comps);
  // prvec(ords);
  // debug(dp);
 
  return 0;
}

Compilation message (stderr)

clo.cpp: In function 'void prvec(VVI&, std::string)':
clo.cpp:19:20: warning: statement has no effect [-Wunused-value]
   19 | #define debug(...) 42
      |                    ^~
clo.cpp:59:3: note: in expansion of macro 'debug'
   59 |   debug(s);
      |   ^~~~~
clo.cpp:19:20: warning: statement has no effect [-Wunused-value]
   19 | #define debug(...) 42
      |                    ^~
clo.cpp:62:5: note: in expansion of macro 'debug'
   62 |     debug(i, v[i]);
      |     ^~~~~
#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...