alexjercan/bugnet huggingface dataset:
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vi c(n);
  vvi a(n, vi(m));
  bitset<12> bb;
  for (int ix = 0; ix < n; ix++) {
    cin >> c.at(ix);
    for (int ix2 = 0; ix2 < m; ix2++) {
      cin >> a.at(ix).at(ix2);
    }
  }
  int64_t purchase = 1000000007;
  for (int ix = 0; ix < (1 << n); ix++) {
    bb = ix;
    bool can = true;
    int64_t tmp = 0;
    vi test(m, 0);
    for (int ix2 = 0; ix2 < n; ix2++) {
      if (bb.test(ix2)) {
        tmp += c.at(ix2);
        for (int ix3 = 0; ix3 < m; ix3++) {
          test.at(ix3) += a.at(ix2).at(ix3);
        }
      }
    }
    for (int ix4 = 0; ix4 < m; ix4++)
      if (test.at(ix4) < x)
        can = false;
    if (can)
      purchase = min(purchase, tmp);
  }
  cout << (purchase != 1000000007 ? purchase : (int64_t)-1) << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vi c(n);
  vvi a(n, vi(m));
  bitset<12> bb;
  for (int ix = 0; ix < n; ix++) {
    cin >> c.at(ix);
    for (int ix2 = 0; ix2 < m; ix2++) {
      cin >> a.at(ix).at(ix2);
    }
  }
  int64_t purchase = 1000000007;
  for (int ix = 0; ix < (1 << n); ix++) {
    bb = ix;
    bool can = true;
    int64_t tmp = 0;
    vi test(n, 0);
    for (int ix2 = 0; ix2 < n; ix2++) {
      if (bb.test(ix2)) {
        tmp += c.at(ix2);
        for (int ix3 = 0; ix3 < m; ix3++) {
          test.at(ix3) += a.at(ix2).at(ix3);
        }
      }
    }
    for (int ix4 = 0; ix4 < m; ix4++)
      if (test.at(ix4) < x)
        can = false;
    if (can)
      purchase = min(purchase, tmp);
  }
  cout << (purchase != 1000000007 ? purchase : (int64_t)-1) << endl;
}
Problem p02683 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <vector>

int main() {
  long long n, m, x;
  long long ans = 1000000000000000;
  bool flag = false;
  std::cin >> n >> m >> x;
  std::vector<long long> C;
  std::vector<std::vector<long long>> A(n, std::vector<long long>(m));
  std::vector<int> N;
  for (int i = 0; i < n; i++) {
    N.push_back(i);
    long long c;
    std::cin >> c;
    C.push_back(c);
    for (int j = 0; j < m; j++)
      std::cin >> A[i][j];
  }

  for (int bit = 0; bit < (1 << n); bit++) {
    long long cost = 0;
    std::vector<long long> M(m, 0);
    for (int i = 0; i < n; i++) {
      if (bit & (1 << i)) {
        cost += C[i];
        for (int j = 0; j < m; j++) {
          M[j] += A[i][j];
        }
      }
    }
    if (*(std::min_element(M.begin(), M.end())) >= x) {
      flag = true;
      ans = std::min(ans, cost);
    }
  }
  if (flag)
    std::cout << ans << '\\n';
  else
    std::cout << -1 << '\\n';
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>

int main() {
  long long n, m, x;
  long long ans = 1000000000000000;
  bool flag = false;
  std::cin >> n >> m >> x;
  std::vector<long long> C;
  std::vector<std::vector<long long>> A(n, std::vector<long long>(m));
  std::vector<int> N;
  for (int i = 0; i < n; i++) {
    N.push_back(i);
    long long c;
    std::cin >> c;
    C.push_back(c);
    for (int j = 0; j < m; j++)
      std::cin >> A[i][j];
  }

  do {
    long long over = 0;
    long long cost = 0;
    std::vector<long long> M(m, 0);
    for (int i = 0; i < n; i++) {
      cost += C[N[i]];
      for (int j = 0; j < m; j++) {
        M[j] += A[N[i]][j];
      }
      if (*(std::min_element(M.begin(), M.end())) >= x) {
        flag = true;
        ans = std::min(ans, cost);
        break;
      }
    }
  } while (std::next_permutation(N.begin(), N.end()));
  if (flag)
    std::cout << ans << '\\n';
  else
    std::cout << -1 << '\\n';
}
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

int main() {
  long n, m, x;
  cin >> n >> m >> x;

  vector<long> c(n, 0);
  vector<vector<long>> a(n, vector<long>(m, 0));

  for (long i = 0; i < n; i++) {
    cin >> c[i];
    for (long j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }

  long min = -1;

  for (long bit = 0; bit < (1 << n); bit++) {
    vector<long> u(m, 0);
    long sum = 0;
    bool flg = true;
    for (long i = 0; i < n; i++) {
      if (bit & (1 << i)) {
        sum += c[i];
        for (long j = 0; j < m; j++) {
          u[j] += a[i][j];
        }
      }
    }

    for (long j = 0; j < m; j++) {
      if (u[j] < x) {
        flg = false;
      }
    }
    if (flg) {
      if (sum < min || min == -1) {
        min = sum;
      }
    }
  }

  cout << min << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

int main() {
  long long n, m, x;
  cin >> n >> m >> x;

  vector<long long> c(n, 0);
  vector<vector<long long>> a(n, vector<long long>(n, 0));

  for (long long i = 0; i < n; i++) {
    cin >> c[i];
    for (long long j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }

  long long min = -1;

  for (long long bit = 0; bit < (1 << n); bit++) {
    vector<long long> u(m, 0);
    long long sum = 0;
    bool flg = true;
    for (long long i = 0; i < n; i++) {
      if (bit & (1 << i)) {
        sum += c[i];
        for (long long j = 0; j < m; j++) {
          u[j] += a[i][j];
        }
      }
    }

    for (long long j = 0; j < m; j++) {
      if (u[j] < x) {
        flg = false;
      }
    }
    if (flg) {
      if (sum < min || min == -1) {
        min = sum;
      }
    }
  }

  cout << min << endl;

  return 0;
}
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n, m, x, a, c, ans;
  cin >> n >> m >> x;
  vector<int> C;
  vector<vector<int>> A(n, vector<int>(m));
  for (int i = 0; i < n; i++) {
    cin >> c;
    C.push_back(c);
    for (int j = 0; j < m; j++) {
      cin >> a;
      A[i][j] = a;
    }
  }
  ans = 10000000;
  int p, ok;
  for (int i = 0; i < (1 << n); i++) {
    p = 0;
    ok = 0;
    vector<int> skill(m);
    for (int j = 0; j < n; j++) {
      if (i & (1 << j)) {
        p += C[j];
        for (int k = 0; k < m; k++) {
          skill[k] += A[j][k];
        }
      }
    }
    for (int l = 0; l < m; l++) {
      if (skill[l] < x) {
        ok = -1;
        break;
      }
    }
    if (ok == 0) {
      if (p < ans) {
        ans = p;
      }
    }
  }
  if (ans == 10000000) {
    ans = -1;
    cout << ans;
  } else {
    cout << ans;
  }
}

Error: -11

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n, m, x, a, c, ans;
  cin >> n >> m >> x;
  vector<int> C;
  vector<vector<int>> A;
  for (int i = 0; i < n; i++) {
    cin >> c;
    C.push_back(c);
    for (int j = 0; j < m; j++) {
      cin >> a;
      A[i][j] = a;
    }
  }
  ans = 10000000;
  int p, ok;
  for (int i = 0; i < (1 << n); i++) {
    p = 0;
    ok = 0;
    vector<int> skill(m);
    for (int j = 0; j < n; j++) {
      if (i & (1 << j)) {
        p += C[j];
        for (int k = 0; k < m; k++) {
          skill[k] += A[j][k];
        }
      }
    }
    for (int l = 0; l < m; l++) {
      if (skill[l] < x) {
        ok = -1;
        break;
      }
    }
    if (ok == 0) {
      if (p < ans) {
        ans = p;
      }
    }
  }
  if (ans == 10000000) {
    ans = -1;
    cout << ans;
  } else {
    cout << ans;
  }
}
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

#include <math.h>
#include <stdio.h>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
const int INF = 0x7f7f7f7f;
int min(int x, int y) { return (x < y) ? x : y; }
int main(void) {
  int N, M, X, check, cost, C[12] = {0}, A[12][12] = {0}, skill[12] = {0},
                            total = INF;
  check = scanf("%d %d %d", &N, &M, &X);
  rep(i, N) {
    check = scanf("%d", &C[i]);
    rep(j, M) check = scanf("%d", &A[i][j]);
  }
  for (int bit = pow(2, N) - 1; ~bit; bit--) {
    cost = 0;
    rep(i, M) skill[i] = 0;
    rep(i, N) if (bit & (int)pow(2, i)) {
      cost += C[i];
      rep(j, M) skill[j] += A[i][j];
    }
    check = 1;
    rep(i, M) if (skill[i] < X) {
      check = 0;
      break;
    }
    if (check)
      total = min(total, cost);
  }
  return printf("%d\\n", total == INF ? -1 : total), 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, N) for (int64_t i = 0; i < (int64_t)N; i++)
#define swap(a, b) ((a != b) && (a += b, b = a - b, a -= b))
typedef vector<vector<int>> Matrix;
const int INF = 1 << 30;
int main() {
  int N, M, X, OK = 0, check = 1;
  int64_t cost = 0, price = 1e18;
  cin >> N >> M >> X;
  vector<int> C(N, 0), score(M, 0);
  vector<vector<int>> A(N, vector<int>(M, 0));
  rep(i, N) {
    cin >> C.at(i);
    rep(j, M) { cin >> A.at(i).at(j); }
  }
  rep(i, N) {
    cost += C.at(i);
    rep(j, M) {
      score.at(i) += A.at(i).at(j);
      if (X >= score.at(i))
        OK = 1;
      else
        OK = 0;
      check &= OK;
    }
    if (check)
      price = min(cost, price);
    cost = 0;
  }
  return cout << price << endl, 0;
}
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using ll = long long int;
using namespace std;

int main() {
  int N, M, X;
  cin >> N >> M >> X;
  vector<vector<int>> A(N, vector<int>(M + 1, 0));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= M; j++) {
      cin >> A[i][j];
    }
  }
  int ans = 100000000;
  for (int i = 1; i < (1 << N); i++) {
    int score = 0;
    vector<int> x(M, 0);
    for (int j = 0; j < N; j++) {
      if ((i >> j) & 1) {
        for (int k = 0; k < M; k++) {
          x[k] += A[j][k + 1];
        }
        score += A[j][0];
      }
    }
    bool flag = true;
    for (int j = 0; j < M; j++) {
      if (x[j] < X) {
        flag = false;
        break;
      }
    }
    if (flag) {
      ans = min(ans, score);
    }
  }
  if (ans == 100000000) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using ll = long long int;
using namespace std;

int main() {
  int N, M, X;
  cin >> N >> M >> X;
  vector<vector<int>> A(N, vector<int>(M + 1, 0));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= M; j++) {
      cin >> A[i][j];
    }
  }
  int ans = 100000000;
  for (int i = 1; i < (1 << 12); i++) {
    int score = 0;
    vector<int> x(M, 0);
    for (int j = 0; j < M; j++) {
      if ((i >> j) & 1) {
        for (int k = 0; k < M; k++) {
          x[k] += A[j][k + 1];
        }
        score += A[j][0];
      }
    }
    bool flag = true;
    for (int j = 0; j < M; j++) {
      if (x[j] < X) {
        flag = false;
        break;
      }
    }
    if (flag) {
      ans = min(ans, score);
    }
  }
  if (ans == 100000000) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }

  return 0;
}
Problem p02683 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <complex>
#include <functional>
#include <iostream>
#include <limits>
#include <numeric>
#include <sstream>
#include <string>

#include <set>
#include <vector>

using namespace std;

int N, M, X;
vector<vector<int>> book_info;

int min_result = 1e9;

void process(int depth, int last, vector<int> score, int price) {
  bool check = true;
  for (auto e : score) {
    if (e < X) {
      check = false;
      break;
    }
  }

  if (check) {
    min_result = min(min_result, price);
    return;
  }

  if (depth == N) {
    return;
  }

  for (int i = last + 1; i < N; i++) {
    for (int j = 0; j < M; j++) {
      score[j] += book_info[i][j + 1];
    }
    process(depth + 1, i, score, price + book_info[i][0]);
    for (int j = 0; j < M; j++) {
      score[j] -= book_info[i][j + 1];
    }
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);

  cin >> N >> M >> X;

  book_info.assign(N, vector<int>(M + 1, 0));

  for (int i = 0; i < N; i++) {
    cin >> book_info[i][0];
    for (int j = 0; j < M; j++) {
      cin >> book_info[i][j + 1];
    }
  }

  process(0, -1, vector<int>(M, 0), 0);

  if (min_result == 1e9) {
    cout << -1;
  } else {
    cout << min_result;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <functional>
#include <iostream>
#include <limits>
#include <numeric>
#include <sstream>
#include <string>

#include <set>
#include <vector>

using namespace std;

int N, M, X;
vector<vector<int>> book_info;

int min_result = 1e9;

void process(int depth, set<int> select, vector<int> score, int price) {
  bool check = true;
  for (auto e : score) {
    if (e < X) {
      check = false;
      break;
    }
  }

  if (check) {
    min_result = min(min_result, price);
    return;
  }

  if (depth == N) {
    return;
  }

  for (int i = 0; i < N; i++) {
    if (select.find(i) != select.end())
      continue;

    select.insert(i);
    for (int j = 0; j < M; j++) {
      score[j] += book_info[i][j + 1];
    }
    process(depth + 1, select, score, price + book_info[i][0]);
    for (int j = 0; j < M; j++) {
      score[j] -= book_info[i][j + 1];
    }
    select.erase(i);
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);

  cin >> N >> M >> X;

  book_info.assign(N, vector<int>(M + 1, 0));

  for (int i = 0; i < N; i++) {
    cin >> book_info[i][0];
    for (int j = 0; j < M; j++) {
      cin >> book_info[i][j + 1];
    }
  }

  process(0, set<int>(), vector<int>(M, 0), 0);

  if (min_result == 1e9) {
    cout << -1;
  } else {
    cout << min_result;
  }

  return 0;
}
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>

std::vector<int> res;

int n, m, x;
std::vector<std::vector<int>> vec;
std::vector<int> book_prices;

int main() {
  std::cin >> n >> m >> x;
  book_prices.assign(n, 0);
  vec.assign(n, std::vector<int>(m, 0));
  for (int i = 0; i < n; i++) {
    std::cin >> book_prices[i];
    for (int j = 0; j < m; j++) {
      std::cin >> vec[i][j];
    }
  }
  for (int i = 0; i < (2 << n); i++) {
    std::vector<int> skill(m, 0);
    int total_price = 0;
    for (int j = 0; j < n; j++) {
      if ((i >> j) & 1) {
        total_price += book_prices[j];
        for (int k = 0; k < m; k++) {
          skill[k] += vec[j][k];
        }
      }
    }
    int min_skill = *std::min_element(skill.begin(), skill.end());
    if (min_skill >= x) {
      res.push_back(total_price);
    }
  }
  if (res.size() > 0) {
    std::cout << *std::min_element(res.begin(), res.end()) << std::endl;
    return 0;
  }
  std::cout << -1 << std::endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>

std::vector<int> res;

int n, m, x;
std::vector<std::vector<int>> vec;
std::vector<int> book_prices;

int main() {
  std::cin >> n >> m >> x;
  book_prices.assign(n, 0);
  vec.assign(n, std::vector<int>(m, 0));
  for (int i = 0; i < n; i++) {
    std::cin >> book_prices[i];
    for (int j = 0; j < m; j++) {
      std::cin >> vec[i][j];
    }
  }
  for (int i = 0; i < (2 << n); i++) {
    std::vector<int> skill(n, 0);
    int total_price = 0;
    for (int j = 0; j < n; j++) {
      if ((i >> j) & 1) {
        total_price += book_prices[j];
        for (int k = 0; k < m; k++) {
          skill[k] += vec[j][k];
        }
      }
    }
    int min_skill = *std::min_element(skill.begin(), skill.end());
    if (min_skill >= x) {
      res.push_back(total_price);
    }
  }
  if (res.size() > 0) {
    std::cout << *std::min_element(res.begin(), res.end()) << std::endl;
    return 0;
  }
  std::cout << -1 << std::endl;
}
Problem p02683 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using lint = long long;
int n, m, x;
vector<int> mem(1 << 13, 1e9);

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  cin >> n >> m >> x;
  vector<int> c(n);
  vector<vector<int>> a(n, vector<int>(m));
  for (int i = 0; i < n; ++i) {
    cin >> c[i];
    for (int j = 0; j < m; ++j)
      cin >> a[i][j];
  }

  // int visited = 0;
  // vector<int> cur(m, 0);
  // int res = f(c, a, visited, cur);

  int res = 1e9;
  int state = 0;
  while (state <= (1 << n) - 1) {
    ++state;

    int cost = 0;
    int ss = state;
    int i = 0;
    vector<int> cur(m, 0);
    while (ss && i < n) {
      if ((ss & 1) == 1) {
        cost += c[i];
        for (int j = 0; j < m; ++j)
          cur[j] += a[i][j];
      }
      ++i;
      ss >>= 1;
    }

    int cnt = 0;
    for (int j = 0; j < m; ++j) {
      if (cur[j] >= x)
        ++cnt;
    }
    if (cnt == m)
      res = min(res, cost);
  }

  if (res >= 1e9)
    cout << "-1" << endl;
  else
    cout << res << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using lint = long long;
int n, m, x;
vector<int> mem(1 << 13, 1e9);

int f(vector<int> &c, vector<vector<int>> &a, int visited, vector<int> &cur) {
  if (mem[visited] != 1e9)
    return mem[visited];
  int res = 1e9;

  int cnt = 0;
  for (int j = 0; j < m; ++j) {
    if (cur[j] >= x)
      ++cnt;
  }
  if (cnt == m)
    return 0;

  for (int i = 0; i < n; ++i) {
    if ((visited & (1 << i)) == 0) {
      visited |= (1 << i);

      for (int j = 0; j < m; ++j) {
        cur[j] += a[i][j];
      }
      res = min(res, c[i] + f(c, a, visited, cur));

      for (int j = 0; j < m; ++j) {
        cur[j] -= a[i][j];
      }
      visited ^= (1 << i);
    }
  }
  mem[visited] = res;
  return res;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  cin >> n >> m >> x;
  vector<int> c(n);
  vector<vector<int>> a(n, vector<int>(m));
  for (int i = 0; i < n; ++i) {
    cin >> c[i];
    for (int j = 0; j < m; ++j)
      cin >> a[i][j];
  }

  int visited = 0;
  vector<int> cur(m, 0);
  int res = f(c, a, visited, cur);
  if (res >= 1e9)
    cout << "-1" << endl;
  else
    cout << res << endl;
  return 0;
}
Problem p02683 (C++) — buggy submission, verdict: Time Limit Exceeded

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, M;
  long X;
  cin >> N >> M >> X;
  long C[N];
  long A[N][M];
  for (int i = 0; i < N; i++) {
    cin >> C[i];
    for (int j = 0; j < M; j++) {
      cin >> A[i][j];
    }
  }

  vector<long long> z(M, 0);
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      z[j] += A[i][j];
    }
  }

  int n = N;
  long ans = -1;
  for (int bit = 0; bit < (1 << n); ++bit) {
    vector<long> skills(M, 0);
    long money = 0;
    for (int i = 0; i < n; ++i) {
      if (bit & (1 << i)) { // 列挙に i が含まれるか
        for (int j = 0; j < M; j++) {
          skills[j] += A[i][j];
        }
        money += C[i];
      }
    }
    bool ok = true;
    for (int i = 0; i < M; i++) {
      if (skills[i] < X) {
        ok = false;
        break;
      }
    }
    if (ok) {
      if (ans == -1)
        ans = money;
      else
        ans = min(money, ans);
    }
  }

  cout << ans << endl;
}

Error: TLE

Fixed submission:

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;

long long f(int k) {
  int sum = 1;
  for (int i = 1; i <= k; ++i) {
    sum *= i;
  }
  return sum;
}

int main() {
  int N, M;
  long X;
  cin >> N >> M >> X;
  long C[N];
  long A[N][M];
  for (int i = 0; i < N; i++) {
    cin >> C[i];
    for (int j = 0; j < M; j++) {
      cin >> A[i][j];
    }
  }

  vector<long long> z(M, 0);
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      z[j] += A[i][j];
    }
  }
  for (int j = 0; j < M; j++) {
    if (z[j] < X) {
      cout << "-1" << endl;
      return 0;
    }
  }

  vector<int> array(N);
  for (int i = 0; i < N; i++) {
    array[i] = i;
  }

  if (N == 1) {
    cout << C[0] << endl;
    return 0;
  }

  long long ans = 0;
  for (long long i = 0; i < f(N); i++) {
    vector<long long> sum(M, 0);
    long long money = 0;
    for (int j = 0; j < N; j++) {
      bool up = true;
      for (int k = 0; k < M; k++) {
        sum[k] += A[array[j]][k];
        if (sum[k] < X)
          up = false;
        // cout<<A[array[j]][k];
      }
      // cout<<endl;
      money += C[array[j]];
      if (up) {
        break;
      }
    }
    if (i == 0) {
      ans = money;
    } else {
      ans = min(money, ans);
    }
    next_permutation(array.begin(), array.end());
  }
  cout << ans << endl;
}
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

template <typename type> type BaseChange(type num, type base, type digit) {
  for (type i = 0; i < digit; i++) {
    num /= base;
  }
  return num % base;
}

int main() {
  // 基本データ入力
  long long n, m, x;
  cin >> n >> m >> x;

  // コストとデータ入力
  vector<long long> c(n);
  vector<vector<long long>> a(n, vector<long long>(m));
  for (int i = 0; i < n; i++) {
    cin >> c[i];
    for (long long j = 0; j < m; j++)
      cin >> a[i][j];
  }

  long long ans = (1 << 30);

  // ビット全探索
  for (long long i = 1; i < (1 << n); i++) {
    long long cost = 0;
    vector<long long> state(m, 0);
    for (long long j = 0; j < n; j++) {
      // 検索文字がhit
      // cout << BaseChange(i,2,j);
      if (BaseChange(i, 2LL, j) == 1) {
        cost += c[j];
        for (long long k = 0; k < m; k++) {
          state[k] += a[j][k];
        }
      }
    }
    // cout << endl;
    // デバッグ用
    // cout << " " << cost << " ";
    // for(int j=0;j<m;j++) cout << state[j] << " ";
    // cout << endl;
    bool check = true;
    for (long long j = 0; j < m; j++) {
      if (state[j] < x)
        check = false;
    }
    if (check)
      ans = min(ans, cost);
  }
  if (ans == (1 << 30))
    ans = -1;
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

template <typename type> type BaseChange(type num, type base, type digit) {
  for (type i = 0; i < digit; i++) {
    num /= base;
  }
  return num % base;
}

int main() {
  // 基本データ入力
  long long n, m, x;
  cin >> n >> m >> x;

  // コストとデータ入力
  vector<long long> c(n);
  vector<vector<long long>> a(n, vector<long long>(n));
  for (int i = 0; i < n; i++) {
    cin >> c[i];
    for (long long j = 0; j < m; j++)
      cin >> a[i][j];
  }

  long long ans = (1 << 30);

  // ビット全探索
  for (long long i = 1; i < (1 << n); i++) {
    long long cost = 0;
    vector<long long> state(m, 0);
    for (long long j = 0; j < n; j++) {
      // 検索文字がhit
      // cout << BaseChange(i,2,j);
      if (BaseChange(i, 2LL, j) == 1) {
        cost += c[j];
        for (long long k = 0; k < m; k++) {
          state[k] += a[j][k];
        }
      }
    }
    // cout << endl;
    // デバッグ用
    // cout << " " << cost << " ";
    // for(int j=0;j<m;j++) cout << state[j] << " ";
    // cout << endl;
    bool check = true;
    for (long long j = 0; j < m; j++) {
      if (state[j] < x)
        check = false;
    }
    if (check)
      ans = min(ans, cost);
  }
  if (ans == (1 << 30))
    ans = -1;
  cout << ans << endl;
}