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

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 1001001001;

int a[12][12];

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> c(n);
  rep(i, n) {
    cin >> c[i];
    rep(j, m) cin >> a[i][j];
  }

  int ans = INF;
  rep(s, 1 << n) {
    int cost = 0;
    vector<int> d(m);
    rep(i, n) {
      if (s >> i & 1) {
        cost += c[i];
        rep(j, m) d[j] += a[i][j];
      }
    }
    bool ok = true;
    rep(j, m) if (d[j] < x) ok = false;
    if (ok)
      ans = min(ans, cost);
  }
  if (ans == INF)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i; i < (n); i++)

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

  int a[15], cost;
  long long ans = 100000000000000000;

  vector<vector<int>> v(n, vector<int>(m + 1));

  rep(i, n) { rep(j, m + 1) cin >> v[i][j]; }

  rep(bit, (1 << n)) {
    cost = 0;
    rep(i, n) {
      if (bit & (1 << i)) {
        cost += v[i][0];
        rep(j, m) { a[j] += v[i][j + 1]; }
      }
    }
    bool ok = true;
    rep(i, m) if (a[i] < x) ok = false;
    if (ok && cost < ans)
      ans = cost;

    rep(i, n) a[i] = 0;
  }

  if (ans == 100000000000000000)
    cout << -1 << endl;
  else
    cout << ans << endl;
}
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dunk(n) cout << n << endl
#define all(v) v.begin(), v.end()
typedef long long ll;

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<vector<int>> a(n, vector<int>(m));
  vector<int> c(n);
  rep(i, n) {
    cin >> c.at(i);
    rep(j, m) { cin >> a.at(i).at(j); }
  }

  int ans = 1001001001;

  rep(i, 1 << n) {
    int cost = 0;
    vector<int> d(m);
    rep(j, n) {
      if (i >> j & 1) {
        cost += c.at(j);
        rep(s, m) d.at(s) += a.at(j).at(s);
      }
    }
    bool ok = true;
    rep(j, m) if (d.at(j) < x) ok = false;
    if (ok)
      ans = min(ans, cost);
  }

  if (ans == 1001001001)
    dunk("-1");
  else
    dunk(ans);

  return 0;
}


Error: 0

Fixed submission:

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dunk(n) cout << n << endl
#define all(v) v.begin(), v.end()
typedef long long ll;

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<vector<int>> a(n, vector<int>(m));
  vector<int> c(m);
  rep(i, n) {
    cin >> c.at(i);
    rep(j, m) { cin >> a.at(i).at(j); }
  }

  int ans = 1001001001;

  rep(i, 1 << n) {
    int cost = 0;
    vector<int> d(m);
    rep(j, n) {
      if (i >> j & 1) {
        cost += c.at(j);
        rep(s, m) d.at(s) += a.at(j).at(s);
      }
    }
    bool ok = true;
    rep(j, m) if (d.at(j) < x) ok = false;
    if (ok)
      ans = min(ans, cost);
  }

  if (ans == 1001001001)
    dunk("-1");
  else
    dunk(ans);

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> c(n);
  vector<vector<int>> a(n, vector<int>(m));

  int min_money = 999999999;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= m; j++) {
      if (j == 0)
        cin >> c.at(i);
      else
        cin >> a.at(i).at(j - 1);
    }
  }

  for (int tmp = 0; tmp < (1 << 12); tmp++) {
    vector<int> understand(m, 0);
    bitset<12> s(tmp);
    int money = 0;

    for (int i = 0; i < n; i++) {
      if (s.test(i)) {
        money += c.at(i);
        for (int j = 0; j < m; j++) {
          understand.at(j) += a.at(i).at(j);
        }
      }
    }

    bool achive = true;
    for (int i = 0; i < m; i++)
      if (understand.at(i) < x)
        achive = false;

    if (achive) {
      if (min_money > money)
        min_money = money;
    }
    money = 0;
  }
  if (min_money == 999999999)
    cout << -1;
  else
    cout << min_money;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> c(n);
  vector<vector<int>> a(n, vector<int>(m));

  int min_money = 999999999;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= m; j++) {
      if (j == 0)
        cin >> c.at(i);
      else
        cin >> a.at(i).at(j - 1);
    }
  }

  for (int tmp = 0; tmp < (1 << 12); tmp++) {
    vector<int> understand(n, 0);
    bitset<12> s(tmp);
    int money = 0;

    for (int i = 0; i < n; i++) {
      if (s.test(i)) {
        money += c.at(i);
        for (int j = 0; j < m; j++) {
          understand.at(j) += a.at(i).at(j);
        }
      }
    }

    bool achive = true;
    for (int i = 0; i < m; i++) {
      // cout << understand.at(i) << endl;
      if (understand.at(i) < x)
        achive = false;
    }
    if (achive) {
      if (min_money == -1 or min_money > money)
        min_money = money;
    }
    money = 0;
  }
  if (min_money == 999999999)
    cout << -1;
  else
    cout << min_money;
}
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N, M, X;
  cin >> N >> M >> X;
  vector<int> price(12, 0);
  vector<vector<int>> add(N, vector<int>(M));
  for (int i = 0; i < N; i++) {
    cin >> price.at(i);
    for (int j = 0; j < M; j++) {
      cin >> add.at(i).at(j);
    }
  }
  int m = 0;
  for (int i = 0; i < N; i++) {
    m += price.at(i);
  }
  bool c = false;
  for (int k = 0; k < (1 << N); k++) {
    vector<int> sum(M, 0);
    bitset<12> buy(k);
    int total = 0;
    for (int l = 0; l < 12; l++) {
      if (buy.test(l)) {
        total += price.at(l);
        for (int i = 0; i < M; i++) {
          sum.at(i) += add.at(l).at(i);
        }
      }
    }
    bool a = true;
    for (int i = 0; i < M; i++) {
      if (sum.at(i) < X) {
        a = false;
      }
    }
    if (a) {
      c = true;
      if (total < m) {
        m = total;
      }
    }
  }
  if (c) {
    cout << m << endl;
  } else {
    cout << -1 << endl;
  }
}

Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 9) >= this->size() (which is 3)


Fixed submission:

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

int main() {
  int N, M, X;
  cin >> N >> M >> X;
  vector<int> price(12, 0);
  vector<vector<int>> add(N, vector<int>(M));
  for (int i = 0; i < N; i++) {
    cin >> price.at(i);
    for (int j = 0; j < M; j++) {
      cin >> add.at(i).at(j);
    }
  }
  int m = 0;
  for (int i = 0; i < N; i++) {
    m += price.at(i);
  }
  bool c = false;
  for (int k = 0; k < (1 << N); k++) {
    vector<int> sum(M, 0);
    bitset<12> buy(k << (12 - N));
    int total = 0;
    for (int l = 0; l < 12; l++) {
      if (buy.test(l)) {
        total += price.at(l);
        for (int i = 0; i < M; i++) {
          sum.at(i) += add.at(l).at(i);
        }
      }
    }
    bool a = true;
    for (int i = 0; i < M; i++) {
      if (sum.at(i) < X) {
        a = false;
      }
    }
    if (a) {
      c = true;
      if (total < m) {
        m = total;
      }
    }
  }
  if (c) {
    cout << m << endl;
  } else {
    cout << -1 << endl;
  }
}
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
const ll MOD = 1000000007;

// nの2^iの位の数を出力する関数
ll pla(ll n, ll i) {
  ll x = pow(2, i + 1), y = pow(2, i);
  return n % x / y;
}

int main() {
  ll N, M, X;
  cin >> N >> M >> X;
  vector<ll> C(N);
  vector<vector<ll>> A(N, vector<ll>(M));
  rep(i, N) {
    cin >> C.at(i);
    rep(j, M) { cin >> A.at(i).at(j); }
  }
  ll kane = 100000000;
  rep(i, pow(2, N)) {
    vector<ll> wis(M);
    rep(j, N) {
      if (pla(i, j) == 1) {
        rep(k, M) { wis.at(k) += A.at(j).at(k); }
      }
    }
    bool a = true;
    rep(j, M) {
      if (wis.at(j) < X) {
        a = false;
      }
    }
    if (a) {
      ll mon = 0;
      rep(j, N) {
        if (pla(i, j) == 1) {
          mon += C.at(j);
        }
      }
      kane = min(kane, mon);
    }
  }
  if (kane != 100000000) {
    cout << kane << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
const ll MOD = 1000000007;

// nの2^iの位の数を出力する関数
ll pla(ll n, ll i) {
  ll x = pow(2, i + 1), y = pow(2, i);
  return n % x / y;
}

int main() {
  ll N, M, X;
  cin >> N >> M >> X;
  vector<ll> C(N);
  vector<vector<ll>> A(N, vector<ll>(M));
  rep(i, N) {
    cin >> C.at(i);
    rep(j, M) { cin >> A.at(i).at(j); }
  }
  ll kane = 100000000;
  rep(i, pow(2, N)) {
    vector<ll> wis(N);
    rep(j, N) {
      if (pla(i, j) == 1) {
        rep(k, M) { wis.at(k) += A.at(j).at(k); }
      }
    }
    bool a = true;
    rep(j, M) {
      if (wis.at(j) < X) {
        a = false;
      }
    }
    if (a) {
      ll mon = 0;
      rep(k, N) {
        if (pla(i, k) == 1) {
          mon += C.at(k);
        }
      }
      kane = min(kane, mon);
    }
  }
  if (kane != 100000000) {
    cout << kane << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
Problem p02683 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
const int INF = 100000000;

int a[12][12];

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> c(n);
  rep(i, n) {
    cin >> c[i];
    rep(j, m) cin >> a[i][j];
  }
  int ans = INF;
  rep(s, 1 << n) {
    int cost = 0;
    vector<int> d(m);
    rep(i, n) {
      if (s >> i & 1) {
        cost = cost + c[i];
        rep(j, m) d[j] += a[i][j];
      }
    }
    bool ok = true;
    rep(j, m) if (d[j] < x) ok = false;
    if (ok)
      ans = min(ans, cost);
  }
  if (ans == INF)
    cout << -1 << endl;
  else
    cout << ans << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int n, m, x;
  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; i < m; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cout << a[i][j] << endl;
    }
  }
  int sum = 0;
  int ans, p = 0;
  for (int tmp = 0; tmp < (1 << 12); tmp++) {
    bitset<12> s(tmp);
    for (int k = 0; k < n; k++) {
      p = 0;
      for (int i = 0; i < m; i++) {
        for (int j = 0; j < n; j++) {
          if (s.test(k)) {
            p = p + a[j][i];
            sum = sum + c[j];
          }
        }
        if (p < x) {
          sum = 100000000;
          break;
        }
      }
      ans = min(sum, ans);
    }
  }
  if (ans != 100000000)
    cout << ans << endl;
  else
    cout << "-1" << endl;
}
Problem p02683 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
int n, m, x;
const int N = 20;
int a[N][N];
int c[N];
int main() {
  int n, m, x;
  cin >> n >> m >> x;
  for (int i = 0; i < n; i++) {
    cin >> c[i];
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  long long ans = LLONG_MAX;
  for (int i = 0; i < (1 << n); i++) {
    vector<int> b(m, 0);
    long long cost = 0;
    for (int j = 0; j < n; j++) {
      if (i >> j & 1) {
        cost += c[j];
        for (int l = 0; l < m; l++) {
          b[l] += a[j][l];
        }
      }
    }
    bool f = true;
    for (int j = 0; j < m; j++) {
      if (b[j] < x) {
        f = false;
        break;
      }
    }
    if (f)
      ans = min(ans, cost);
  }
  if (ans == LLONG_MAX) {
    cout << "-1";
  } else
    cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
int n, m, x;
const int N = 20;
int a[N][N];
int c[N];

long long res = LLONG_MAX;

void solve(string s) {
  //    cout << s << endl;
  vector<int> t(m + 1, 0);
  long long temp = 0;
  for (int i = 0; i < s.size(); i++) {
    // check if possible to achieve using this books
    // if yes write to res;
    int x = s[i] - '0';
    x--;
    for (int j = 0; j < m; j++) {
      t[j] += a[x][j];
    }
    temp += c[x];
  }
  bool f = true;
  for (int i = 0; i < m; i++) {
    if (t[i] < x) {
      f = false;
      break;
    }
  }
  if (f)
    res = min(res, temp);
  for (int i = 1; i <= n; i++) {
    if (s.find(to_string(i)) == std::string::npos) {
      solve(s + to_string(i));
    }
  }
}
int main() {
  cin >> n >> m >> x;
  for (int i = 0; i < n; i++) {
    cin >> c[i];
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  solve("");
  if (res == LLONG_MAX) {
    cout << "-1";
  } else
    cout << res << endl;
}
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// using Bint = mp::cpp_int;
// using Real = mp::number<mp::cpp_dec_float<1024>>;

int main() {
  int N, M, X;
  cin >> N >> M >> X;
  vector<int> C(12);
  vector<vector<int>> A(12, vector<int>(12));
  rep(i, N) {
    cin >> C.at(i);
    rep(j, M) { cin >> A.at(i).at(j); }
  }

  int ans = INF;

  for (int tmp = 0; tmp < (1 << N); tmp++) {
    bitset<12> s(tmp);

    vector<int> a_sum(M, 0);
    int price = 0;

    rep(i, N) {
      if (s.test(i)) {
        price += C.at(i);
        rep(j, M) { a_sum.at(j) += A.at(i).at(j); }
      }
    }

    bool flag = true;
    rep(i, M) {
      if (a_sum.at(i) < X) {
        flag = false;
        break;
      }
    }

    if (flag) {
      ans = min(ans, price);
    }
  }

  if (ans == INF)
    cout << -1 << endl;
  else
    cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// using Bint = mp::cpp_int;
// using Real = mp::number<mp::cpp_dec_float<1024>>;

int main() {
  int N, M, X;
  cin >> N >> M >> X;
  vector<int> C(12);
  vector<vector<int>> A(12, vector<int>(12));
  rep(i, N) {
    cin >> C.at(i);
    rep(j, M) { cin >> A.at(i).at(j); }
  }

  int ans = INF;

  for (int tmp = 0; tmp < (1 << N); tmp++) {
    bitset<12> s(tmp);

    vector<int> A_sum(N, 0);
    int price = 0;

    rep(i, N) {
      if (s.test(i)) {
        price += C.at(i);
        rep(j, M) { A_sum.at(j) += A.at(i).at(j); }
      }
    }

    bool flag = true;
    rep(i, M) {
      if (A_sum.at(i) < X) {
        flag = false;
        break;
      }
    }

    if (flag) {
      ans = min(ans, price);
    }
  }

  if (ans == INF)
    cout << -1 << endl;
  else
    cout << ans << endl;
}
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long int
using namespace std;
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}

int cost(vector<int> &v1, vector<vector<int>> &v, int x) {
  vector<ll> ans(v[0].size(), 0);
  for (int i = 0; i < v.size(); i++) {
    if (v1[i] != 0) {
      for (int j = 0; j < v[0].size(); j++) {
        ans[j] = ans[j] + v[i][j];
      }
    }
  }
  ll cost1 = -1;
  for (int i = 1; i < ans.size(); i++) {
    if (ans[i] < x) {
      return cost1;
    }
  }
  return ans[0];
}

vector<int> to_binary(int i, int n) {
  int cnt = n - 1;
  vector<int> t(n, 0);
  while (i > 0) {
    int x = i % 2;
    t[cnt] = x;
    i = i / 2;
    cnt--;
  }
  return t;
}

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

  vector<vector<int>> v;

  for (int i = 0; i < n; i++) {
    vector<int> dummy;
    for (int j = 0; j < m + 1; j++) {
      int x1;
      cin >> x1;
      dummy.push_back(x1);
    }
    v.push_back(dummy);
  }
  int r = (1 << n) - 1;
  int mini = INT_MAX;
  for (int i = 1; i <= r; i++) {
    vector<int> v1;
    v1 = to_binary(i, n);
    int xy = cost(v1, v, x);
    if (xy != -1) {
      mini = min(xy, mini);
    }
  }
  if (mini == INT_MAX) {
    cout << -1 << endl;
  } else {
    cout << mini << endl;
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}

int cost(vector<int> &v1, vector<vector<int>> &v, int x) {
  vector<int> ans(v[0].size(), 0);
  for (int i = 0; i < v1.size(); i++) {
    if (v1[i] != 0) {
      for (int j = 0; j < v[0].size(); j++) {
        ans[j] = ans[j] + v[i][j];
      }
    }
  }
  int cost1 = -1;
  for (int i = 1; i < ans.size(); i++) {
    if (ans[i] < x) {
      return cost1;
    }
  }
  return ans[0];
}

vector<int> to_binary(int i, int m) {
  int cnt = m - 1;
  vector<int> t(m, 0);
  while (i > 0) {
    int x = i % 2;
    t[cnt] = x;
    i = i / 2;
    cnt--;
  }
  return t;
}

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

  vector<vector<int>> v;

  for (int i = 0; i < n; i++) {
    vector<int> dummy;
    for (int j = 0; j < m + 1; j++) {
      int x1;
      cin >> x1;
      dummy.push_back(x1);
    }
    v.push_back(dummy);
  }
  int r = (1 << n) - 1;
  int mini = INT_MAX;
  for (int i = 1; i <= r; i++) {
    vector<int> v1;
    v1 = to_binary(i, m);
    int xy = cost(v1, v, x);
    if (xy != -1) {
      mini = min(xy, mini);
    }
  }
  if (mini == INT_MAX) {
    cout << -1 << endl;
  } else {
    cout << mini << endl;
  }
}
Problem p02683 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define int long long
#define pb push_back
#define ff first
#define ss second
int ans1 = LONG_LONG_MAX;
void backtrack(vector<int> &c, vector<vector<int>> &a, int n, int m, int x,
               int idx, vector<int> &ans, int sum) {
  // cout<<"CAlled:\\n";
  int k;
  for (k = 0; k < ans.size(); k++) {
    if (ans[k] > 0) {
      break;
    }
  }
  if (k == ans.size())
    ans1 = min(ans1, sum);
  for (int i = idx; i < n; i++) {
    for (int j = 0; j < m; j++)
      ans[j] = ans[j] - a[i][j];
    backtrack(c, a, n, m, x, i + 1, ans, sum + c[i]);
    for (int j = 0; j < m; j++)
      ans[j] = ans[j] + a[i][j];
  }
}
int32_t main() {
  int n, m, x;
  cin >> n >> m >> x;

  vector<int> c(n);
  vector<vector<int>> a(n, vector<int>(m));
  vector<int> ans(m, x);
  for (int i = 0; i < n; i++) {
    cin >> c[i];
    for (int j = 0; j < m; j++)
      cin >> a[i][j];
  }
  backtrack(c, a, n, m, x, 0, ans, 0);
  if (ans1 == LONG_LONG_MAX)
    cout << -1;
  else
    cout << ans1;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define MOD 998244353
#define pb push_back
#define ll long long int
#define con 1000000007
using namespace std;
ll mx;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll i, j, k, n, m;
  ll t;

  cin >> n >> m >> mx;
  vector<ll> a(n, 0);
  for (i = 0; i < n; i++)
    a[i] = i + 1;
  ll b[n][m + 1];
  for (i = 0; i < n; i++) {
    for (j = 0; j < m + 1; j++)
      cin >> b[i][j];
  }
  ll maxi = INT_MAX;
  do {
    vector<ll> ch(m + 1, 0);
    ll o = 0;
    for (i = 0; i < n; i++) {
      ll count = 0;

      for (j = 1; j <= m; j++) {
        ch[j] += b[a[i] - 1][j];
        if (ch[j] >= mx)
          count++;
      }
      o += b[a[i] - 1][0];
      if (count == m) {
        maxi = min(maxi, o);
        break;
      }
    }
    if (maxi == INT_MAX) {
      cout << -1;
      return 0;
    }
    if (i == n) {
      cout << maxi;
      return 0;
    }
  } while (next_permutation(a.begin(), a.end()));
  cout << maxi;
}
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

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

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
typedef long long ll;
typedef pair<int, int> pii;
const int inf = 1010001000;
const ll INF = 1001000100010001000;
const int mod = (int)1e9 + 7;

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> c(n);
  vector<vector<int>> a(n, vector<int>(m));
  int ans = inf;
  rep(i, 0, n) {
    cin >> c.at(i);
    rep(j, 0, m) { cin >> a.at(i).at(j); }
  }
  for (int bit = 0; bit < (1 << n); bit++) {
    vector<int> s(m, 0);
    int cost = 0;
    for (int i = 0; i < n; i++) {
      if (bit & (1 << i)) {
        cost += c.at(i);
        rep(j, 0, m) { s.at(j) += a.at(i).at(j); }
      }
    }
    bool ch = true;
    rep(j, 0, m) {
      if (s.at(j) < x)
        ch = false;
    }
    if (ch)
      ans = min(ans, cost);
  }
  if (ans == inf) {
    cout << "-1" << endl;
    return 0;
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

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

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
typedef long long ll;
typedef pair<int, int> pii;
const int inf = 1010001000;
const ll INF = 1001000100010001000;
const int mod = (int)1e9 + 7;

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> c(n);
  vector<vector<int>> a(n, vector<int>(m));
  int ans = inf;
  rep(i, 0, n) {
    cin >> c.at(i);
    rep(j, 0, m) { cin >> a.at(i).at(j); }
  }
  for (int bit = 0; bit < (1 << n); bit++) {
    vector<int> s(n, 0);
    int cost = 0;
    for (int i = 0; i < n; i++) {
      if (bit & (1 << i)) {
        cost += c.at(i);
        rep(j, 0, m) { s.at(j) += a.at(i).at(j); }
      }
    }
    bool ch = true;
    rep(j, 0, m) {
      if (s.at(j) < x)
        ch = false;
    }
    if (ch)
      ans = min(ans, cost);
  }
  if (ans == inf) {
    cout << "-1" << endl;
    return 0;
  }
  cout << ans << endl;
  return 0;
}