Problem p02920 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>     // minmax, sort, swap
#include <climits>       // INT_MIN, LLONG_MIN
#include <cmath>         // long, trig, pow
#include <cstdio>        // printf, scanf
#include <deque>         // deque
#include <functional>    // std::function<void(int)>
#include <iomanip>       // cout<<setprecision(n)
#include <iostream>      // cin, cout, cerr, clog
#include <map>           // key-value pairs sorted by keys
#include <numeric>       // iota, accumulate, inner_product
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <string>        // string, stoi, to_string
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <vector>        // vector

#define rep(i, n) for (int i = 0; i < (n); i++)
#define ENDL '\n'
#define print(i) std::cout << (i) << '\n'

#define int long long // at least int64 > 9*10^18
#define all(v) (v).begin(), (v).end()
/* libraries */

struct FastIO {
  FastIO() {
    std::cin.tie(0);
    std::ios_base::sync_with_stdio(0);
  }
} fastio;

int zpowl(int v, int k) {
  int r(1), t(v);
  while (k) {
    if (k & 1)
      r *= t;
    t *= t;
    k >>= 1;
  }
  return r;
}

signed main() {
  int n;
  std::cin >> n;
  int m = zpowl(2, n);
  std::vector<int> s(m);
  rep(i, m) std::cin >> s[i];
  std::multiset<int, std::greater<int>> set;
  for (int i : s)
    set.emplace(i);
  std::vector<int> created;
  auto it = set.begin();
  created.emplace_back(*it);
  set.erase(it);
  rep(i, n) {
    for (int c : created) {
      auto it = set.upper_bound(c);
      if (it == set.end()) {
        print("No");
        return 0;
      }
      created.emplace_back(*it);
      set.erase(it);
    }
  }
  print("Yes");

  return 0;
}


Fixed submission:
#include <algorithm>     // minmax, sort, swap
#include <climits>       // INT_MIN, LLONG_MIN
#include <cmath>         // long, trig, pow
#include <cstdio>        // printf, scanf
#include <deque>         // deque
#include <functional>    // std::function<void(int)>
#include <iomanip>       // cout<<setprecision(n)
#include <iostream>      // cin, cout, cerr, clog
#include <map>           // key-value pairs sorted by keys
#include <numeric>       // iota, accumulate, inner_product
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <string>        // string, stoi, to_string
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <vector>        // vector

#define rep(i, n) for (int i = 0; i < (n); i++)
#define ENDL '\n'
#define print(i) std::cout << (i) << '\n'

#define int long long // at least int64 > 9*10^18
#define all(v) (v).begin(), (v).end()
/* libraries */

struct FastIO {
  FastIO() {
    std::cin.tie(0);
    std::ios_base::sync_with_stdio(0);
  }
} fastio;

int zpowl(int v, int k) {
  int r(1), t(v);
  while (k) {
    if (k & 1)
      r *= t;
    t *= t;
    k >>= 1;
  }
  return r;
}

signed main() {
  int n;
  std::cin >> n;
  int m = zpowl(2, n);
  std::vector<int> s(m);
  rep(i, m) std::cin >> s[i];
  std::multiset<int, std::greater<int>> set;
  for (int i : s)
    set.emplace(i);
  std::vector<int> created;
  auto it = set.begin();
  created.emplace_back(*it);
  set.erase(it);
  rep(i, n) {
    rep(j, zpowl(2, i)) {
      auto it = set.upper_bound(created[j]);
      if (it == set.end()) {
        print("No");
        return 0;
      }
      created.emplace_back(*it);
      set.erase(it);
    }
  }
  print("Yes");

  return 0;
}