prithivMLmods/Coder-Stat huggingface dataset:
Problem p02683 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define F first
#define S second
using namespace std;

ll MOD = 1000000007;
int ans = INT_MAX;
int fd = -1;
int n, m, x;
void back(int cost, int ind, vector<vector<int>> &mp, vector<int> &c,
          vector<int> vals) {
  int f = 1;
  for (int i = 0; i < m; i++) {
    if (vals[i] < x) {
      f = 0;
      break;
    }
  }
  // cout<<ind<<" "<<f<<endl;
  if (f == 1) {
    ans = min(ans, cost);
    fd = 1;
  }
  if (ind == n)
    return;
  cost += c[ind];

  for (int i = 0; i < m; i++) {
    vals[i] += mp[ind][i];
  }
  back(cost, ind + 1, mp, c, vals);
  cost -= c[ind];
  for (int i = 0; i < m; i++) {
    vals[i] -= mp[ind][i];
  }
  back(cost, ind + 1, mp, c, vals);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m >> x;
  vector<int> c(n, 0);
  vector<int> t(m, 0);
  vector<vector<int>> mp(n, t);
  for (int i = 0; i < n; i++) {
    cin >> c[i];
    for (int j = 0; j < m; j++)
      cin >> mp[i][j];
  }
  vector<int> vals(n, 0);
  back(0, 0, mp, c, vals);
  if (fd == -1)
    ans = -1;
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define F first
#define S second
using namespace std;

ll MOD = 1000000007;
int ans = INT_MAX;
int fd = -1;
int n, m, x;
void back(int cost, int ind, vector<vector<int>> &mp, vector<int> &c,
          vector<int> vals) {
  int f = 1;
  for (int i = 0; i < m; i++) {
    if (vals[i] < x) {
      f = 0;
      break;
    }
  }
  // cout<<ind<<" "<<f<<endl;
  if (f == 1) {
    ans = min(ans, cost);
    fd = 1;
  }
  if (ind == n)
    return;
  cost += c[ind];

  for (int i = 0; i < m; i++) {
    vals[i] += mp[ind][i];
  }
  back(cost, ind + 1, mp, c, vals);
  cost -= c[ind];
  for (int i = 0; i < m; i++) {
    vals[i] -= mp[ind][i];
  }
  back(cost, ind + 1, mp, c, vals);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m >> x;
  vector<int> c(n, 0);
  vector<int> t(m, 0);
  vector<vector<int>> mp(n, t);
  for (int i = 0; i < n; i++) {
    cin >> c[i];
    for (int j = 0; j < m; j++)
      cin >> mp[i][j];
  }
  vector<int> vals(m, 0);
  back(0, 0, mp, c, vals);
  if (fd == -1)
    ans = -1;
  cout << ans << endl;
  return 0;
}
Problem p02683 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
// #define ll long long
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int(i) = (int)(n)-1; (i) >= 0; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define all(x) (x).begin(), (x).end()
ll t1, t2, t3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;

ll n, m, x;
vector<vector<ll>> vec(12, vector<ll>(12, 0));
vector<ll> c(12);
ll ans = INFLONG;

void dfs(ll num, ll cost, vector<ll> arr) {
  // cout << num << endl;
  if (num == n) {
    bool can = true;
    rep(i, m) {
      if (arr[i] < x) {
        can = false;
      }
    }
    if (can) {
      chmin(ans, cost);
    }
    return;
  }
  dfs(num + 1, cost, arr);
  rep(i, m) { arr[i] += vec[num][i]; }
  dfs(num + 1, cost + c[num], arr);
}

int main() {
  cin >> n >> m >> x;
  rep(i, n) {
    cin >> c[i];
    rep(j, m) { cin >> vec[i][j]; }
  }
  vector<ll> arr(n, 0);
  dfs(0, 0, arr);
  if (ans == INFLONG) {
    ans = -1;
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
// #define ll long long
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int(i) = (int)(n)-1; (i) >= 0; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define all(x) (x).begin(), (x).end()
ll t1, t2, t3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;

ll n, m, x;
vector<vector<ll>> vec(12, vector<ll>(12, 0));
vector<ll> c(12);
ll ans = INFLONG;

void dfs(ll num, ll cost, vector<ll> arr) {
  // cout << num << endl;
  if (num == n) {
    bool can = true;
    rep(i, m) {
      if (arr[i] < x) {
        can = false;
      }
    }
    if (can) {
      chmin(ans, cost);
    }
    return;
  }
  dfs(num + 1, cost, arr);
  rep(i, m) { arr[i] += vec[num][i]; }
  dfs(num + 1, cost + c[num], arr);
}

int main() {
  cin >> n >> m >> x;
  rep(i, n) {
    cin >> c[i];
    rep(j, m) { cin >> vec[i][j]; }
  }
  vector<ll> arr(m, 0);
  dfs(0, 0, arr);
  if (ans == INFLONG) {
    ans = -1;
  }
  cout << ans << endl;
}
Problem p02683 (C++)

Buggy submission (status: 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>;
int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> C(12);
  vector<vector<int>> pa(n, vector<int>(m));
  rep(i, n) {
    cin >> C.at(i);
    rep(j, m) { cin >> pa.at(i).at(j); }
  }
  int ans = 100100100;
  int count = 0;

  for (int tmp = 0; tmp < (1 << 12); tmp++) {
    bitset<12> s(tmp);
    // (ビット列sに対する処理)
    count = 0;
    vector<int> Ans(n);
    rep(i, n) {

      if (s.test(i)) {
        count += C.at(i);
        rep(j, m) { Ans.at(j) += pa.at(i).at(j); }
      }
    }
    bool can = true;
    rep(i, m) {
      if (Ans.at(i) < x) {
        can = false;
      }
    }
    if (can) {
      ans = min(count, ans);
    }
  }
  if (ans == 100100100) {
    cout << -1 << endl;
  } else
    cout << ans << endl;
}

Fixed submission:
#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>;
int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> C(12);
  vector<vector<int>> pa(n, vector<int>(m));
  rep(i, n) {
    cin >> C.at(i);
    rep(j, m) { cin >> pa.at(i).at(j); }
  }
  int ans = 100100100;
  int count = 0;

  for (int tmp = 0; tmp < (1 << 12); tmp++) {
    bitset<12> s(tmp);
    // (ビット列sに対する処理)
    count = 0;
    vector<int> Ans(m);
    rep(i, n) {

      if (s.test(i)) {
        count += C.at(i);
        rep(j, m) { Ans.at(j) += pa.at(i).at(j); }
      }
    }
    bool can = true;
    rep(i, m) {
      if (Ans.at(i) < x) {
        can = false;
      }
    }
    if (can) {
      ans = min(count, ans);
    }
  }
  if (ans == 100100100) {
    cout << -1 << endl;
  } else
    cout << ans << endl;
}
Problem p02683 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <vector>
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.at(i);
    for (int j = 0; j < m; ++j) {
      cin >> a.at(i).at(j);
    }
  }

  int ans = 1000000000;
  for (int i = 0; i <= (1 << n) - 1; ++i) {
    int sum_c = 0;
    vector<int> sum_a(n, 0);
    for (int j = 0; j < n; ++j) {
      if (i >> j & 1) {
        sum_c += c.at(j);
        for (int k = 0; k < m; ++k) {
          sum_a.at(k) += a.at(j).at(k);
        }
      }
    }
    bool f = true;
    for (int k = 0; k < m; ++k) {
      if (sum_a.at(k) < x) {
        f = false;
        break;
      }
    }
    if (f && sum_c < ans) {
      ans = sum_c;
    }
  }
  if (ans == 1000000000) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}


Fixed submission:
#include <iostream>
#include <vector>
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.at(i);
    for (int j = 0; j < m; ++j) {
      cin >> a.at(i).at(j);
    }
  }

  int ans = 1000000000;
  for (int i = 0; i <= (1 << n) - 1; ++i) {
    int sum_c = 0;
    vector<int> sum_a(m, 0);
    for (int j = 0; j < n; ++j) {
      if (i >> j & 1) {
        sum_c += c.at(j);
        for (int k = 0; k < m; ++k) {
          sum_a.at(k) += a.at(j).at(k);
        }
      }
    }
    bool f = true;
    for (int k = 0; k < m; ++k) {
      if (sum_a.at(k) < x) {
        f = false;
        break;
      }
    }
    if (f && sum_c < ans) {
      ans = sum_c;
    }
  }
  if (ans == 1000000000) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}
Problem p02683 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<vector<ll>> a(n);
  vector<ll> c(n);
  ll ans = (1 << 29);
  for (int i = 0; i < n; i++) {
    cin >> c.at(i);
    a.at(i).resize(m);
    for (int j = 0; j < m; j++) {
      cin >> a.at(i).at(j);
    }
  }

  for (int i = 0; i < (1 << n); i++) {
    ll sum = 0;
    vector<ll> d(n);
    for (int j = 0; j < n; j++) {
      if ((i >> j) & 1) {
        for (int k = 0; k < m; k++) {
          d.at(k) += a.at(j).at(k);
        }
        sum += c.at(j);
      }
    }

    bool flg = true;
    for (int k = 0; k < m; k++) {
      if (d.at(k) < x) {
        flg = false;
      }
    }
    if (flg) {
      ans = min(ans, sum);
    }
  }

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

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<vector<ll>> a(n);
  vector<ll> c(n);
  ll ans = (1 << 29);
  for (int i = 0; i < n; i++) {
    cin >> c.at(i);
    a.at(i).resize(m);
    for (int j = 0; j < m; j++) {
      cin >> a.at(i).at(j);
    }
  }

  for (int i = 0; i < (1 << n); i++) {
    ll sum = 0;
    vector<ll> d(m);
    for (int j = 0; j < n; j++) {
      if ((i >> j) & 1) {
        for (int k = 0; k < m; k++) {
          d.at(k) += a.at(j).at(k);
        }
        sum += c.at(j);
      }
    }

    bool flg = true;
    for (int k = 0; k < m; k++) {
      if (d.at(k) < x) {
        flg = false;
      }
    }
    if (flg) {
      ans = min(ans, sum);
    }
  }

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

  return 0;
}
Problem p02683 (C++)

Buggy submission (status: Time Limit Exceeded):
/*
    Mbak Sana Dong
    Mbak Chaeyoung Dong
*/
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
vector<int> vi[105];
int cost[105];
int main() {
  int n, i, j, k, x, y, ans, curr, temp, m;
  int tc;
  cin >> n >> m >> x;
  for (i = 1; i <= n; i++) {
    cin >> cost[i];
    for (j = 1; j <= m; j++) {
      cin >> curr;
      vi[i].push_back(curr);
    }
  }
  int chaeng = 1e9;
  int maxi = 1 << n;
  for (i = 0; i < maxi; i++) {
    curr = 0;
    int master[n + 5];
    memset(master, 0, sizeof(master));
    for (j = 0; j < n; j++) {
      if (i & (1 << j)) {
        curr += cost[j + 1];
        for (k = 0; k < m; k++) {
          master[k] += vi[j + 1][k];
        }
      }
    }
    int mini = 1e9;
    for (j = 0; j < m; j++) {
      mini = min(mini, master[j]);
    }
    if (mini >= x) {
      chaeng = min(chaeng, curr);
    }
  }
  if (chaeng == 1e9)
    cout << "-1";
  else
    cout << chaeng;
  cout << endl;
  return 0;
}


Fixed submission:
/*
    Mbak Sana Dong
    Mbak Chaeyoung Dong
*/
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
vector<int> vi[105];
int cost[105];
int main() {
  int n, i, j, k, x, y, ans, curr, temp, m;
  int tc;
  cin >> n >> m >> x;
  for (i = 1; i <= n; i++) {
    cin >> cost[i];
    for (j = 1; j <= m; j++) {
      cin >> curr;
      vi[i].push_back(curr);
    }
  }
  int chaeng = 1e9;
  int maxi = 1 << n;
  for (i = 0; i < maxi; i++) {
    curr = 0;
    int master[m + 2];
    memset(master, 0, sizeof(master));
    for (j = 0; j < n; j++) {
      if (i & (1 << j)) {
        curr += cost[j + 1];
        for (k = 0; k < m; k++) {
          master[k] += vi[j + 1][k];
        }
      }
    }
    int mini = 1e9;
    for (j = 0; j < m; j++) {
      mini = min(mini, master[j]);
    }
    if (mini >= x) {
      chaeng = min(chaeng, curr);
    }
  }
  if (chaeng == 1e9)
    cout << "-1";
  else
    cout << chaeng;
  cout << endl;
  return 0;
}
Problem p02683 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  long n, t, a, b, c, m, x, mi, aux;
  cin >> n >> m >> x;
  deque<long> A[n];
  long R[n];
  long au[n];
  for (int i = 0; i < n; i++) {
    cin >> R[i];
    for (int l = 0; l < m; l++) {
      cin >> a;
      A[i].push_back(a);
    }
  }
  mi = 10000000;
  for (int i = 0; i < (1 << n); i++) {
    memset(au, 0, sizeof(au));
    c = 0;
    aux = 0;
    for (int j = 0; j < n; j++) {
      if (i & (1 << j)) {
        aux = aux + R[j];
        for (int l = 0; l < m; l++) {
          if (au[l] != -1)
            au[l] = au[l] + A[j][l];
          if (au[l] >= x) {
            au[l] = -1;
            c++;
          }
        }
      }
    }
    if (c == m)
      mi = min(mi, aux);
  }
  if (mi == 10000000)
    cout << "-1" << endl;
  else
    cout << mi << endl;
  return 0;
}


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

int main() {
  long n, t, a, b, c, m, x, mi, aux;
  cin >> n >> m >> x;
  deque<long> A[n];
  long R[n];
  long au[m];
  for (int i = 0; i < n; i++) {
    cin >> R[i];
    for (int l = 0; l < m; l++) {
      cin >> a;
      A[i].push_back(a);
    }
  }
  mi = 10000000;
  for (int i = 0; i < (1 << n); i++) {
    memset(au, 0, sizeof(au));
    c = 0;
    aux = 0;
    for (int j = 0; j < n; j++) {
      if (i & (1 << j)) {
        aux = aux + R[j];
        for (int l = 0; l < m; l++) {
          if (au[l] != -1)
            au[l] = au[l] + A[j][l];
          if (au[l] >= x) {
            au[l] = -1;
            c++;
          }
        }
      }
    }
    if (c == m)
      mi = min(mi, aux);
  }
  if (mi == 10000000)
    cout << "-1" << endl;
  else
    cout << mi << endl;
  return 0;
}
Problem p02683 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  ll n, m, x;
  cin >> n >> m >> x;
  vector<int> C(n);
  vector<vector<ll>> A(n, vector<ll>(m));

  for (int i = 0; i < n; i++) {
    cin >> C[i];
    for (int j = 0; j < m; j++) {
      cin >> A[i][j];
    }
  }

  for (int i = 1; i < m; i++) {
    if (std::accumulate(A[i].begin(), A[i].end(), 0) < x) {
      cout << -1;
      return 0;
    }
  }

  ll ans = 1e8;
  for (int i = 0; i < 1 << n; i++) {
    ll cost = 0;
    vector<int> d(m);
    for (int j = 0; j < n; j++) {
      if (i >> j & 1) {
        cost += C[j];
        for (int k = 0; k < m; k++)
          d[k] += A[j][k];
      }
    }
    bool flag = true;

    for (int j = 0; j < m; j++) {
      if (d[j] < x) {
        flag = false;
      }
    }
    if (flag)
      ans = std::min(ans, cost);
  }
  if (ans == 1e8)
    cout << -1 << endl;
  else
    cout << ans;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  ll n, m, x;
  cin >> n >> m >> x;
  vector<int> C(n);
  vector<vector<ll>> A(n, vector<ll>(m));

  for (int i = 0; i < n; i++) {
    cin >> C[i];
    for (int j = 0; j < m; j++) {
      cin >> A[i][j];
    }
  }

  /*for (int i = 1; i < m; i++) {
          if (std::accumulate(A[i].begin(), A[i].end(), 0) < x) {
                  cout << -1;
                  return 0;
          }
  }*/

  ll ans = 1e8;
  for (int i = 0; i < 1 << n; i++) {
    ll cost = 0;
    vector<int> d(m);
    for (int j = 0; j < n; j++) {
      if (i >> j & 1) {
        cost += C[j];
        for (int k = 0; k < m; k++)
          d[k] += A[j][k];
      }
    }
    bool flag = true;

    for (int j = 0; j < m; j++) {
      if (d[j] < x) {
        flag = false;
      }
    }
    if (flag)
      ans = std::min(ans, cost);
  }
  if (ans == 1e8)
    cout << -1 << endl;
  else
    cout << ans;

  return 0;
}
Problem p02683 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, M, X; // N冊の参考書、M個のアルゴリズム、理解度X
  cin >> N >> M >> X;
  vector<vector<int>> A(N, vector<int>(M));
  vector<int> kingaku(N);
  for (int i = 0; i < N; i++) {
    cin >> kingaku[i];
    for (int j = 0; j < M; j++) {
      cin >> A.at(i).at(j);
    }
  }
  int resultSmall = -1;
  for (int tmp = 0; tmp < (1 << 12); tmp++) {
    bitset<12> s(tmp);
    int count = 0;
    vector<int> rikaido(M, 0);
    if (s.test(N))
      break;

    for (int i = 0; i < N; i++) {
      if (s.test(i)) {
        count += kingaku[i];

        for (int j = 0; j < M; j++) {
          rikaido[j] += A.at(i).at(j);
        }
      }
    }
    bool flag = true;

    for (int i = 0; i < M; i++) {
      if (rikaido[i] < X) {
        flag = false;
        break;
      }
    }
    if (flag) {
      if (resultSmall == -1) {
        resultSmall = count;
      } else {
        resultSmall = min(resultSmall, count);
      }
    }
  }
  cout << resultSmall << endl;
}

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

int main() {
  int N, M, X; // N冊の参考書、M個のアルゴリズム、理解度X
  cin >> N >> M >> X;
  vector<vector<int>> A(N, vector<int>(M));
  vector<int> kingaku(N);
  for (int i = 0; i < N; i++) {
    cin >> kingaku[i];
    for (int j = 0; j < M; j++) {
      cin >> A.at(i).at(j);
    }
  }
  int resultSmall = -1;
  for (int tmp = 0; tmp < (1 << 12); tmp++) {
    bitset<12> s(tmp);
    int count = 0;
    vector<int> rikaido(M, 0);
    // if (s.test(N)) break;

    for (int i = 0; i < N; i++) {
      if (s.test(i)) {
        count += kingaku[i];

        for (int j = 0; j < M; j++) {
          rikaido[j] += A.at(i).at(j);
        }
      }
    }
    bool flag = true;

    for (int i = 0; i < M; i++) {
      if (rikaido[i] < X) {
        flag = false;
        break;
      }
    }
    if (flag) {
      if (resultSmall == -1) {
        resultSmall = count;
      } else {
        resultSmall = min(resultSmall, count);
      }
    }
  }
  cout << resultSmall << endl;
}
Problem p02683 (C++)

Buggy submission (status: Runtime Error):
// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2020 Bjarni Dagur Thor Karason

#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (__typeof(a) i = (a); i < (b); i++)
#define MP make_pair
#define PB push_back
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
#define INF 1000000000
#define PI 3.14159265359

int n, m, x, ans = INF;
vi cost, vals[13], cur;

bool valid() {
  for (auto u : cur) {
    if (u < x)
      return false;
  }
  return true;
}

void dp(int at, int spent) {
  if (valid()) {
    ans = min(ans, spent);
    return;
  }
  if (at == n)
    return;
  for (int i = 0; i < m; i++) {
    cur[i] += vals[at][i];
  }
  dp(at + 1, spent + cost[at]);
  for (int i = 0; i < m; i++) {
    cur[i] -= vals[at][i];
  }
  dp(at + 1, spent);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> m >> x;
  cost.resize(m);
  cur.resize(m, 0);
  for (int i = 0; i < n; i++) {
    cin >> cost[i];
    for (int j = 0; j < m; j++) {
      int in;
      cin >> in;
      vals[i].PB(in);
    }
  }
  dp(0, 0);
  cout << (ans == INF ? -1 : ans) << endl;

  return 0;
}

Fixed submission:
// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2020 Bjarni Dagur Thor Karason

#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (__typeof(a) i = (a); i < (b); i++)
#define MP make_pair
#define PB push_back
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
#define INF 1000000000
#define PI 3.14159265359

int n, m, x, ans = INF;
vi cost, vals[13], cur;

bool valid() {
  for (auto u : cur) {
    if (u < x)
      return false;
  }
  return true;
}

void dp(int at, int spent) {
  if (valid()) {
    ans = min(ans, spent);
    return;
  }
  if (at == n)
    return;
  for (int i = 0; i < m; i++) {
    cur[i] += vals[at][i];
  }
  dp(at + 1, spent + cost[at]);
  for (int i = 0; i < m; i++) {
    cur[i] -= vals[at][i];
  }
  dp(at + 1, spent);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> m >> x;
  cost.resize(n);
  cur.resize(m, 0);
  for (int i = 0; i < n; i++) {
    cin >> cost[i];
    for (int j = 0; j < m; j++) {
      int in;
      cin >> in;
      vals[i].PB(in);
    }
  }
  dp(0, 0);
  cout << (ans == INF ? -1 : ans) << endl;

  return 0;
}
Problem p02683 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define lint long long
using namespace std;

int main() {

  lint N, M, X;
  cin >> N >> M >> X;

  vector<lint> C(N);
  vector<vector<lint>> A(N, vector<lint>(M));
  vector<vector<lint>> rikai(pow(2, N), vector<lint>(M));
  vector<lint> price(pow(2, N));
  vector<bool> able(pow(2, N), false);

  for (lint i = 0; i < N; i++) {
    cin >> C[i];
    for (lint j = 0; j < M; j++) {
      cin >> A[i][j];
    }
  }

  // priceとrikaiを計算
  for (lint i = 1; i <= pow(2, N); i++) {
    lint tmp = i;
    for (lint j = 0; j < N; j++) {

      price[i - 1] += (tmp % 2) * C[j];

      for (lint k = 0; k < M; k++) {
        rikai[i - 1][k] += (tmp % 2) * A[j][k];
      }

      tmp = tmp / 2;
    }
  }

  // able判定
  for (lint i = 0; i < pow(2, N); i++) {
    sort(rikai[i].begin(), rikai[i].end());
    if (rikai[i][0] >= X)
      able[i] = true;
  }

  vector<lint> price_sort(0);

  for (int i = 0; i < pow(2, N); i++) {
    if (able[i])
      price_sort.push_back(price[i]);
  }

  if (price_sort.size() == 0)
    cout << -1 << endl;

  sort(price_sort.begin(), price_sort.end());

  cout << price_sort[0] << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define lint long long
using namespace std;

int main() {

  lint N, M, X;
  cin >> N >> M >> X;

  vector<lint> C(N);
  vector<vector<lint>> A(N, vector<lint>(M));
  vector<vector<lint>> rikai(pow(2, N), vector<lint>(M));
  vector<lint> price(pow(2, N));
  vector<bool> able(pow(2, N), false);

  for (lint i = 0; i < N; i++) {
    cin >> C[i];
    for (lint j = 0; j < M; j++) {
      cin >> A[i][j];
    }
  }

  // priceとrikaiを計算
  for (lint i = 1; i <= pow(2, N); i++) {
    lint tmp = i;
    for (lint j = 0; j < N; j++) {

      price[i - 1] += (tmp % 2) * C[j];

      for (lint k = 0; k < M; k++) {
        rikai[i - 1][k] += (tmp % 2) * A[j][k];
      }

      tmp = tmp / 2;
    }
  }

  // able判定
  for (lint i = 0; i < pow(2, N); i++) {
    sort(rikai[i].begin(), rikai[i].end());
    if (rikai[i][0] >= X)
      able[i] = true;
  }

  vector<lint> price_sort(0);

  for (int i = 0; i < pow(2, N); i++) {
    if (able[i])
      price_sort.push_back(price[i]);
  }

  if (price_sort.size() == 0)
    cout << "-1" << endl;
  else {
    sort(price_sort.begin(), price_sort.end());
    cout << price_sort[0] << endl;
  }
}
Problem p02683 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define VI vector<int>
#define VL vector<ll>
#define PII pair<int, int>
#define VII vector<PII>
#define mp make_pair
#define pb push_back
#define vt vector
#define PI acos(-1)
#define ld long double
#define endl "\n"
#define all(c) (c).begin(), (c).end()
#define ft first
#define sd second
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define F0R(i, b) for (int i = 0; i < b; ++i)
#define RF0R(i, b) for (int i = b; i >= 0; --i)
const ll inf = 1e18;
const int MxN = 100001;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n, m, x;
  cin >> n >> m >> x;
  vt<int> c(n);
  vt<vt<int>> A(n, vt<int>(m));

  F0R(i, n) {
    cin >> c[i];
    F0R(j, n)
    cin >> A[i][j];
  }
  int ans = INT_MAX;
  F0R(i, (1 << n)) {
    int cost = 0;
    vt<int> skills(m);
    F0R(j, n) {
      if ((i >> j) & 1) {
        // cout << 1 ;
        F0R(k, m)
        skills[k] += A[j][k];
        cost += c[j];
      }
      // cout <<0;
    }
    // cout << endl ;
    bool ok = true;
    F0R(j, m) {
      if (skills[j] < x) {
        ok = false;
        break;
      }
    }
    if (ok) {
      ans = min(ans, cost);
    }
  }
  if (ans == INT_MAX)
    cout << -1;
  else
    cout << ans;
  return 0;
}


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

#define ll long long
#define VI vector<int>
#define VL vector<ll>
#define PII pair<int, int>
#define VII vector<PII>
#define mp make_pair
#define pb push_back
#define vt vector
#define PI acos(-1)
#define ld long double
#define endl "\n"
#define all(c) (c).begin(), (c).end()
#define ft first
#define sd second
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define F0R(i, b) for (int i = 0; i < b; ++i)
#define RF0R(i, b) for (int i = b; i >= 0; --i)
const ll inf = 1e18;
const int MxN = 100001;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n, m, x;
  cin >> n >> m >> x;
  vt<int> c(n);
  vt<vt<int>> A(n, vt<int>(m));

  F0R(i, n) {
    cin >> c[i];
    F0R(j, m)
    cin >> A[i][j];
  }
  int ans = INT_MAX;
  F0R(i, (1 << n)) {
    int cost = 0;
    vt<int> skills(m);
    F0R(j, n) {
      if ((i >> j) & 1) {
        // cout << 1 ;
        F0R(k, m)
        skills[k] += A[j][k];
        cost += c[j];
      }
      // cout <<0;
    }
    // cout << endl ;
    bool ok = true;
    F0R(j, m) {
      if (skills[j] < x) {
        ok = false;
        break;
      }
    }
    if (ok) {
      ans = min(ans, cost);
    }
  }
  if (ans == INT_MAX)
    cout << -1;
  else
    cout << ans;
  return 0;
}
Problem p02683 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) x.begin(), x.end()
#define mod 1000000007
typedef long long ll;

int n, m, x;
vector<vector<int>> vec;
ll smallest = 1000000000000;

void dfs(vector<int> v, vector<bool> flag, int length) {
  if (v.size() == length) {
    vector<int> xVec(m, 0);
    ll sum = 0;
    rep(i, v.size()) {
      rep(j, m + 1) {
        if (j == 0) {
          sum += vec[v[i]][j];
        } else {
          xVec[j - 1] += vec[v[i]][j];
        }
      }
    }
    bool overX = true;
    rep(i, m) {
      if (xVec[i] < x)
        overX = false;
    }
    if (overX) {
      smallest = min(smallest, sum);
    }
  } else {
    rep(i, n) {
      if (!flag[i]) {
        v.push_back(i);
        flag[i] = true;
        dfs(v, flag, length);
        v.pop_back();
        flag[i] = false;
      }
    }
  }
}

int main() {
  cin >> n >> m >> x;
  rep(i, n) {
    vector<int> tmp;
    int c;
    cin >> c;
    tmp.push_back(c);
    rep(j, m) {
      int num;
      cin >> num;
      tmp.push_back(num);
    }
    vec.push_back(tmp);
  }
  for (int i = 1; i <= n; i++) {
    rep(j, n) {
      vector<int> tmp;
      vector<bool> flagVec(n, false);
      tmp.push_back(j);
      flagVec[j] = true;
      dfs(tmp, flagVec, i);
      tmp.pop_back();
      flagVec[j] = false;
    }
  }
  if (smallest == 1000000000000)
    cout << -1 << endl;
  else
    cout << smallest << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) x.begin(), x.end()
#define mod 1000000007
typedef long long ll;

int n, m, x;
vector<vector<int>> vec;
ll smallest = 1000000000000;

void dfs(vector<int> v, vector<bool> flag, int length) {
  if (v.size() == length) {
    vector<int> xVec(m, 0);
    ll sum = 0;
    rep(i, v.size()) {
      rep(j, m + 1) {
        if (j == 0) {
          sum += vec[v[i]][j];
        } else {
          xVec[j - 1] += vec[v[i]][j];
        }
      }
    }
    bool overX = true;
    rep(i, m) {
      if (xVec[i] < x)
        overX = false;
    }
    if (overX) {
      smallest = min(smallest, sum);
    }
  } else {
    for (int i = v.back() + 1; i < n; i++) {
      if (!flag[i]) {
        v.push_back(i);
        flag[i] = true;
        dfs(v, flag, length);
        v.pop_back();
        flag[i] = false;
      }
    }
  }
}

int main() {
  cin >> n >> m >> x;
  rep(i, n) {
    vector<int> tmp;
    int c;
    cin >> c;
    tmp.push_back(c);
    rep(j, m) {
      int num;
      cin >> num;
      tmp.push_back(num);
    }
    vec.push_back(tmp);
  }
  for (int i = 1; i <= n; i++) {
    rep(j, n) {
      vector<int> tmp;
      vector<bool> flagVec(n, false);
      tmp.push_back(j);
      flagVec[j] = true;
      dfs(tmp, flagVec, i);
      tmp.pop_back();
      flagVec[j] = false;
    }
  }
  if (smallest == 1000000000000)
    cout << -1 << endl;
  else
    cout << smallest << endl;
  return 0;
}
Problem p02683 (C++)

Buggy submission (status: 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>(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;
}

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>(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;
}
Problem p02683 (C++)

Buggy submission (status: 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(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;
}

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(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;
}
Problem p02683 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
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; j < M; j++) {
      cin >> A[i][j];
    }
  }
  int sum0 = 1200000;
  bool ans = false;
  for (int tmp = 1; tmp < (1 << 12); tmp++) {
    bitset<12> s(tmp);
    if (s.count() != 12 && s.test(N))
      break;
    vector<int> Adash(M);
    int sum1 = 0;
    for (int i = 0; i < 12; i++) {
      if (s.test(i)) {
        sum1 += C[i];
        for (int j = 0; j < M; j++) {
          Adash[j] += A[i][j];
        }
      }
    }
    bool ans1 = true;
    for (int j = 0; j < M; j++) {
      if (Adash[j] < X)
        ans1 = false;
    }
    if (ans1) {
      sum0 = min(sum0, sum1);
      ans = true;
    }
  }
  if (ans)
    cout << sum0 << endl;
  else
    cout << -1 << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
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; j < M; j++) {
      cin >> A[i][j];
    }
  }
  int sum0 = 1200000;
  bool ans = false;
  for (int tmp = 1; tmp < (1 << 12); tmp++) {
    bitset<12> s(tmp);
    if (N != 12) {
      if (s.test(N))
        break;
    }
    vector<int> Adash(M);
    int sum1 = 0;
    for (int i = 0; i < 12; i++) {
      if (s.test(i)) {
        sum1 += C[i];
        for (int j = 0; j < M; j++) {
          Adash[j] += A[i][j];
        }
      }
    }
    bool ans1 = true;
    for (int j = 0; j < M; j++) {
      if (Adash[j] < X)
        ans1 = false;
    }
    if (ans1) {
      sum0 = min(sum0, sum1);
      ans = true;
    }
  }
  if (ans)
    cout << sum0 << endl;
  else
    cout << -1 << endl;
}
Problem p02683 (Python)

Buggy submission (status: Runtime Error):
n, m, x = map(int, input().split())
prace = []
know = []
for i in range(n):
    acc = list(map(int, input().split()))
    prace.append(acc[0])
    know.append(acc[1:])

ans = 10**10
for i in range(2**n):
    und = [0 for i in range(m)]
    f = "{:b}".format(i)
    s = f.zfill(m)
    mm = 0
    for j in range(len(s)):
        if s[j] == "1":
            for k in range(m):
                und[k] += know[j][k]
            mm += prace[j]
    for j in range(m):
        if und[j] < x:
            break
    else:
        ans = min(ans, mm)
if ans == 10**10:
    print(-1)
else:
    print(ans)


Fixed submission:
n, m, x = map(int, input().split())
prace = []
know = []
for i in range(n):
    acc = list(map(int, input().split()))
    prace.append(acc[0])
    know.append(acc[1:])

ans = 10**10
for i in range(2**n):
    und = [0 for i in range(m)]
    f = "{:b}".format(i)
    s = f.zfill(n)
    mm = 0
    for j in range(len(s)):
        if s[j] == "1":
            for k in range(m):
                und[k] += know[j][k]
            mm += prace[j]
    for j in range(m):
        if und[j] < x:
            break
    else:
        ans = min(ans, mm)
if ans == 10**10:
    print(-1)
else:
    print(ans)
Problem p02683 (C++)

Buggy submission (status: 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(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;
}

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(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;
}
Problem p02683 (C++)

Buggy submission (status: 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 << (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;
  }
}

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);
    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 (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

bool compPair(const pint &arg1, const pint &arg2) {
  return arg1.first > arg2.first;
}
template <class T> void chmax(T &a, T b) {
  if (a < b) {
    a = b;
  }
}
template <class T> void chmin(T &a, T b) {
  if (a > b) {
    a = b;
  }
}

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

  vector<vector<int>> a(n, vector<int>(n, 0));
  vector<int> c(n);
  for (int in = 0; in < n; in++) {
    cin >> c.at(in);
    for (int im = 0; im < m; im++) {
      cin >> a.at(in).at(im);
    }
  }

  bool flg;
  int ans = 1e9, anstmp;
  for (int ib = 0; ib < (1 << n); ib++) {
    vector<int> algo(m);
    anstmp = 0;
    flg = true;
    for (int in = 0; in < n; in++) {
      if (((ib >> in) & 1)) {
        for (int im = 0; im < m; im++) {
          algo.at(im) += a.at(in).at(im);
        }
        anstmp += c.at(in);
      }
    }
    for (int im = 0; im < m; im++) {
      if (algo.at(im) < x) {
        flg = false;
      }
    }
    if (flg)
      ans = min(ans, anstmp);
  }

  if (ans == 1e9)
    ans = -1;
  cout << ans << endl;
  return 0;
}


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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

bool compPair(const pint &arg1, const pint &arg2) {
  return arg1.first > arg2.first;
}
template <class T> void chmax(T &a, T b) {
  if (a < b) {
    a = b;
  }
}
template <class T> void chmin(T &a, T b) {
  if (a > b) {
    a = b;
  }
}

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

  vector<vector<int>> a(n, vector<int>(m, 0));
  vector<int> c(n);
  for (int in = 0; in < n; in++) {
    cin >> c.at(in);
    for (int im = 0; im < m; im++) {
      cin >> a.at(in).at(im);
    }
  }

  bool flg;
  int ans = 1e9, anstmp;
  for (int ib = 0; ib < (1 << n); ib++) {
    vector<int> algo(m);
    anstmp = 0;
    flg = true;
    for (int in = 0; in < n; in++) {
      if (((ib >> in) & 1)) {
        for (int im = 0; im < m; im++) {
          algo.at(im) += a.at(in).at(im);
        }
        anstmp += c.at(in);
      }
    }
    for (int im = 0; im < m; im++) {
      if (algo.at(im) < x) {
        flg = false;
      }
    }
    if (flg)
      ans = min(ans, anstmp);
  }

  if (ans == 1e9)
    ans = -1;
  cout << ans << endl;
  return 0;
}
Problem p02683 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
#include <vector>

const int MAX = 1001001001;

int main() {

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

  int answer = MAX;
  for (int i = 0; i < 1 << N; i++) {
    int cost = 0;
    std::vector<int> skill(M);
    for (int j = 0; j < N; j++) {
      if (i >> j & 1) {
        cost += C[j];
        for (int k = 0; k < M; k++)
          skill[k] += A[j][k];
      }
    }
    int count_error = 0;
    for (int j = 0; j < M; j++) {
      if (skill[j] < X)
        count_error = 1;
    }
    if (count_error == 0)
      answer = std::min(cost, answer);
  }

  if (answer == MAX)
    std::cout << -1 << std::endl;
  else
    std::cout << answer << std::endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
#include <vector>

const int MAX = 1001001001;

int main() {

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

  int answer = MAX;
  for (int i = 0; i < 1 << N; i++) {
    int cost = 0;
    std::vector<int> skill(M);
    for (int j = 0; j < N; j++) {
      if (i >> j & 1) {
        cost += C[j];
        for (int k = 0; k < M; k++)
          skill[k] += A[j][k];
      }
    }
    int count_error = 0;
    for (int j = 0; j < M; j++) {
      if (skill[j] < X)
        count_error = 1;
    }
    if (count_error == 0)
      answer = std::min(cost, answer);
  }

  if (answer == MAX)
    std::cout << -1 << std::endl;
  else
    std::cout << answer << std::endl;
  return 0;
}
Problem p02683 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

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

  int ans = 2000000000;
  for (int tmp = 0; tmp < (1 << 12); tmp++) {
    bitset<12> s(tmp);
    if (s.test(N) && N < 12)
      break;
    int cost = 0;
    for (int i = 0; i < N; i++) {
      if (s.test(i)) {
        cost += c[i];
        for (int j = 0; j < M; j++) {
          MAX[j] += A[i][j];
        }
      }
    }
    bool b = true;
    for (int i = 0; i < M; i++) {
      if (MAX[i] < X)
        b = false;
    }
    if (b)
      ans = min(ans, cost);
    MAX.assign(M, 0);
  }

  cout << (ans == 2000000000 ? -1 : ans) << endl;
}

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

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

  int ans = 2000000000;
  for (int tmp = 0; tmp < (1 << 12); tmp++) {
    bitset<13> s(tmp);
    if (s.test(N) && N < 12)
      break;
    int cost = 0;
    for (int i = 0; i < N; i++) {
      if (s.test(i)) {
        cost += c[i];
        for (int j = 0; j < M; j++) {
          MAX[j] += A[i][j];
        }
      }
    }
    bool b = true;
    for (int i = 0; i < M; i++) {
      if (MAX[i] < X)
        b = false;
    }
    if (b)
      ans = min(ans, cost);
    MAX.assign(M, 0);
  }

  cout << (ans == 2000000000 ? -1 : ans) << endl;
}