Language: C++

#include <iostream>
#include <set>

int main() {
  size_t N;  // 宝箱の個数
  size_t M;  // 鍵の個数
  std::cin >> N >> M;

  // 各宝箱を開けられる最安値の鍵を調べる
  const uint32_t INVALID_PRICE = 100001;
  const size_t INVALID_KEY_INDEX = 1001;
  uint32_t min_prices[12];
  size_t key_indices[12];
  for (size_t i = 0; i < N; ++i) {
    min_prices[i] = INVALID_PRICE;
    key_indices[i] = INVALID_KEY_INDEX;
  }
  for (size_t i = 0; i < M; ++i) {
    uint32_t price;
    size_t count;
    std::cin >> price >> count;
    for (size_t j = 0; j < count; ++j) {
      size_t box;
      std::cin >> box;
      if (price < min_prices[box - 1]) {
        min_prices[box - 1] = price;
        key_indices[box - 1] = i;
      }
    }
  }

  // すべての宝箱を開けるために必要な総費用を計算する
  int64_t result = 0;
  std::set<uint32_t> used_key_set;
  for (size_t i = 0; i < N; ++i) {
    // いずれかの宝箱が開けられない場合
    if (key_indices[i] == INVALID_KEY_INDEX) {
      result = -1;
      break;
    }

    // まだ使っていない鍵を計上する
    if (used_key_set.find(key_indices[i] != used_key_set.end())) {
      result += min_prices[i];
      used_key_set.insert(key_indices[i]);
    }
  }

  std::cout << result;  
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:10:9: error: 'uint32_t' does not name a type
   10 |   const uint32_t INVALID_PRICE = 100001;
      |         ^~~~~~~~
a.cc:3:1: note: 'uint32_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
    2 | #include <set>
  +++ |+#include <cstdint>
    3 | 
a.cc:12:3: error: 'uint32_t' was not declared in this scope
   12 |   uint32_t min_prices[12];
      |   ^~~~~~~~
a.cc:12:3: note: 'uint32_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
a.cc:15:5: error: 'min_prices' was not declared in this scope
   15 |     min_prices[i] = INVALID_PRICE;
      |     ^~~~~~~~~~
a.cc:15:21: error: 'INVALID_PRICE' was not declared in this scope
   15 |     min_prices[i] = INVALID_PRICE;
      |                     ^~~~~~~~~~~~~
a.cc:19:13: error: expected ';' before 'price'
   19 |     uint32_t price;
      |             ^~~~~~
      |             ;
a.cc:21:17: error: 'price' was not declared in this scope
   21 |     std::cin >> price >> count;
      |                 ^~~~~
a.cc:25:19: error: 'min_prices' was not declared in this scope
   25 |       if (price < min_prices[box - 1]) {
      |                   ^~~~~~~~~~
a.cc:34:20: error: template argument 2 is invalid
   34 |   std::set<uint32_t> used_key_set;
      |                    ^
a.cc:34:20: error: template argument 3 is invalid
a.cc:43:22: error: request for member 'find' in 'used_key_set', which is of non-class type 'int'
   43 |     if (used_key_set.find(key_indices[i] != used_key_set.end())) {
      |                      ^~~~
a.cc:43:58: error: request for member 'end' in 'used_key_set', which is of non-class type 'int'
   43 |     if (used_key_set.find(key_indices[i] != used_key_set.end())) {
      |                                                          ^~~
a.cc:44:17: error: 'min_prices' was not declared in this scope
   44 |       result += min_prices[i];
      |                 ^~~~~~~~~~
a.cc:45:20: error: request for member 'insert' in 'used_key_set', which is of non-class type 'int'
   45 |       used_key_set.insert(key_indices[i]);
      |                    ^~~~~~