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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;

int main() {
  //    cout << fixed << setprecision(10);
  long long N, M, X;
  cin >> N >> M >> X;

  vector<vector<long long>> input;

  for (int i = 0; i < N; i++) {
    input.push_back(vector<long long>(M + 1));
    cin >> input[i][0];
    for (int j = 0; j < M; j++) {
      cin >> input[i][j + 1];
    }
  }

  long long minimum = -1;
  for (int k = 0; k < (2 << N); k++) {
    vector<long long> result(M + 1);
    for (int i = 0; i < N; i++) {
      if ((k >> i) & 1) {
        result[0] += input[i][0];
        for (int j = 0; j < M; j++) {
          result[j + 1] += input[i][j + 1];
        }
      }
    }

    bool isOk = true;
    for (int l = 1; l <= M; l++) {
      isOk = isOk & (result[l] >= X);
    }
    if (isOk && (minimum > result[0] || minimum == -1)) {
      minimum = result[0];
    }
  }

  cout << minimum;
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;

int main() {
  //    cout << fixed << setprecision(10);
  long long N, M, X;
  cin >> N >> M >> X;

  long long C;
  vector<long long> A(M);
  vector<vector<long long>> results;
  for (int i = 0; i < (2 << N); i++) {
    vector<long long> result(N + 1);
    results.push_back(result);
  }

  for (int i = 0; i < N; i++) {
    cin >> C;
    for (int j = 0; j < M; j++) {
      cin >> A[j];
    }
    for (int k = 0; k < (2 << N); k++) {
      if ((k >> i) & 1) {
        results[k][0] += C;
        for (int j = 0; j < M; j++) {
          results[k][j + 1] += A[j];
        }
      }
    }
  }

  long long minimum = -1;
  for (int k = 0; k < (2 << N); k++) {
    bool isOk = true;
    for (int l = 1; l <= M; l++) {
      isOk = isOk & (results[k][l] >= X);
    }
    if (isOk && (minimum > results[k][0] || minimum == -1)) {
      minimum = results[k][0];
    }
  }

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

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

using namespace std;

const int INF = 1001001001;
int a[12][12];

int main() {
  ios::sync_with_stdio(false);
  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(i, 1 << n) {
    int cost = 0;
    vector<int> exp(m);
    rep(j, n) {
      if (i >> j & 1) {
        cost += c[j];
        rep(k, m) exp[k] += a[j][k];
      }
    }
    bool ok = true;
    rep(j, m) if (exp[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>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;

using namespace std;

const int INF = 1001001;
int a[12][12];

int main() {
  ios::sync_with_stdio(false);
  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(i, 1 << n) {
    int cost = 0;
    vector<int> exp(m);
    rep(j, n) {
      if (i >> j & 1) {
        cost += c[j];
        rep(k, m) exp[k] += a[i][k];
      }
    }
    bool ok = true;
    rep(j, m) if (exp[j] < x) ok = false;
    if (ok)
      ans = min(ans, cost);
  }

  if (ans == INF)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}
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;
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(i, 1 << N) {
    int cost = 0;
    vector<int> skill(M);
    rep(j, N) {
      if (i >> j & 1) {
        cost += C[j];
        rep(k, M) skill[k] += A[j][k];
      }
    }
    bool OK = 1;
    rep(l, M) if (skill[l] < X) OK = 0;
    if (OK)
      ans = min(ans, cost);
  }

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


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
const int inf = 1001001001;
int main() {
  int N, M, X;
  vector<int> C(N);
  int A[12][12];
  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];
    }
  }
  int ans = inf;
  rep(i, 1 << N) {
    int cost = 0;
    vector<int> skill(M);
    for (int j = 0; j < N; i++) {
      if ((i >> j) & 1) {
        cost += C[j];
        for (int k = 0; k < M; i++) {
          skill[k] += A[j][k];
        }
      }
    }
    bool OK = 1;
    rep(k, M) {
      if (skill[k] < X) {
        OK = 0;
      }
    }
    if (OK) {
      ans = min(ans, cost);
    }
  }

  if (ans == inf) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
}
Problem p02683 (C++) — buggy submission, verdict: 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(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;
}

Error: 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(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;
}
Problem p02683 (C++) — buggy submission, verdict: 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[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;
}


Error: TLE

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[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;
}
Problem p02683 (C++) — buggy submission, verdict: 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[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;
}


Error: 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[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;
}
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll ans = -1;
ll n, m, x;
void dfs(ll h, vector<ll> k, ll sum, vector<vector<ll>> b) {
  bool f = 0;
  for (ll i = 0; i < m; i++)
    if (k[i] < x) {
      f = 1;
      break;
    }
  if (!f) {
    if (ans == -1)
      ans = sum;
    ans = min(ans, sum);
    return;
  }
  for (ll i = h; i < n; i++) {
    vector<ll> l;
    l = k;
    for (ll j = 1; j <= m; j++)
      l[j - 1] += b[i][j];
    dfs(i + 1, l, sum + b[i][0], b);
  }
}
int main() {
  cin >> n >> m >> x;
  vector<vector<ll>> b(n, vector<ll>(m + 1));
  for (ll i = 0; i < n; i++) {
    for (ll j = 0; j < m + 1; j++)
      cin >> b[i][j];
  }
  vector<ll> k(m);
  dfs(0, k, 0, b);
  cout << ans;
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll ans = -1;
ll n, m, x;
vector<vector<ll>> b;
void dfs(ll h, vector<ll> k, ll sum) {
  bool f = 0;
  for (ll i = 0; i < m; i++)
    if (k[i] < x) {
      f = 1;
      break;
    }
  if (!f) {
    if (ans == -1)
      ans = sum;
    ans = min(ans, sum);
    return;
  }
  for (int i = h; i < n; i++) {
    vector<ll> l;
    l = k;
    for (ll j = 1; j <= m; j++)
      l[j - 1] += b[i][j];
    dfs(i + 1, l, sum + b[i][0]);
  }
}
int main() {
  cin >> n >> m >> x;
  b.resize(n);
  for (ll i = 0; i < n; i++) {
    b[i].resize(m + 1);
    for (ll j = 0; j < m + 1; j++)
      cin >> b[i][j];
  }
  vector<ll> k(n);
  dfs(0, k, 0);
  cout << ans;
  return 0;
}
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
using namespace std;

long long n, m, x;
long long XX[12];

void init_XX() {
  for (long long i = 0; i < m; i++) {
    XX[i] = 0;
  }
}

int main() {

  cin >> n >> m >> x;

  long long a[n][m];
  long long c[n];

  for (long long y = 0; y < n; y++) {
    for (long long x = 0; x < m + 1; x++) {
      if (x == 0) {
        cin >> c[y];
      } else {
        cin >> a[y][x - 1];
      }
    }
  }

  long long min_money = 1e9;
  long long cost = 0;

  bool flag = true;

  for (long long bit = 0; bit < (1 << n); bit++) {
    flag = true;
    init_XX();
    cost = 0;

    for (long long y = 0; y < n; y++) {
      if (bit & (1 << y)) {
        cost = cost + c[y];
        for (long long i = 0; i < m; i++) {
          XX[i] = XX[i] + a[y][i];
        }
      }
    }

    for (long long i = 0; i < m; i++) {
      if (XX[i] < x) {
        flag = false;
        break;
      }
    }
    if (flag == true) {
      min_money = min(cost, min_money);
    }
  }

  // printf("money %d\\n", min_money);

  if (min_money != 1e9) {
    printf("%lld\\n", min_money);
  } else {
    printf("-1\\n");
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
using namespace std;

int n, m, x;
int X[12];
int XX[12];
void init_XX() {
  for (int i = 0; i < m; i++) {
    XX[i] = 0;
  }
}

int main() {

  cin >> n >> m >> x;

  int a[n][m];
  int c[n];

  for (int i = 0; i < m; i++) {
    X[i] = 0;
    XX[i] = 0;
  }

  for (int y = 0; y < n; y++) {
    for (int x = 0; x < m + 1; x++) {
      if (x == 0) {
        cin >> c[y];
      } else {
        cin >> a[y][x];
      }
    }
  }

  int min_money = 1e9;
  int cost = 0;

  bool flag = true;

  for (int bit = 0; bit < (1 << n); bit++) {
    flag = true;
    init_XX();
    cost = 0;

    for (int y = 0; y < n; y++) {
      if (bit & (1 << y)) {
        cost = cost + c[y];
        for (int i = 0; i < m; i++) {
          XX[i] = XX[i] + a[y][i];
        }
      }
    }

    for (int i = 0; i < m; i++) {
      if (XX[i] < x) {
        flag = false;
        break;
      }
    }

    if (flag == true) {
      min_money = min(cost, min_money);
    }
  }

  // printf("money %d\\n", min_money);

  if (min_money != 1e9) {
    printf("%d\\n", min_money);
  } else {
    printf("-1\\n");
  }

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

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define mod 1000000007
#define pb push_back
ll a[13][13], c[13];

void rec(ll i, ll n, ll m, ll x, vector<ll> &v, ll ct, vector<ll> &ans) {
  if (i >= n)
    return;
  vector<ll> vp(v);
  ll lg = 0, cp = ct;
  ct += c[i];

  for (ll j = 0; j < m; j++) {
    v[j] += a[i][j];
    if (v[j] >= x)
      lg++;
  }
  if (lg == m) {
    ans.push_back(ct);
    rec(i + 1, n, m, x, vp, cp, ans);
  } else {
    rec(i + 1, n, m, x, vp, cp, ans);

    rec(i + 1, n, m, x, v, ct, ans);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  ll i, n, n2, m, t, j, l, pos, mpos, f = 0, k, p, n1, z, q, x, y, x1, y1, x2,
                                      y2;

  /*cin>>t;


 while(t--)
{


}*/
  cin >> n >> m >> x;
  vector<ll> ans;
  for (i = 0; i < n; i++) {
    cin >> c[i];

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

  vector<ll> v(j, 0);
  rec(0, n, m, x, v, 0, ans);
  // vector<ll> v2(n,0);
  // rec(1,n,m,x,v2,0,ans);
  if (ans.size() == 0)
    cout << "-1";
  else
    cout << *min_element(ans.begin(), ans.end());

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define mod 1000000007
#define pb push_back
ll a[13][13], c[13];

void rec(ll i, ll n, ll m, ll x, vector<ll> &v, ll ct, vector<ll> &ans) {
  if (i >= n)
    return;
  vector<ll> vp(v);
  ll lg = 0, cp = ct;
  ct += c[i];

  for (ll j = 0; j < m; j++) {
    v[j] += a[i][j];
    if (v[j] >= x)
      lg++;
  }
  if (lg == m) {
    ans.push_back(ct);
    return;
  }
  rec(i + 1, n, m, x, vp, cp, ans);

  rec(i + 1, n, m, x, v, ct, ans);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  ll i, n, n2, m, t, j, l, pos, mpos, f = 0, k, p, n1, z, q, x, y, x1, y1, x2,
                                      y2;

  /*cin>>t;


 while(t--)
{


}*/
  cin >> n >> m >> x;
  vector<ll> ans;
  for (i = 0; i < n; i++) {
    cin >> c[i];

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

  vector<ll> v(n, 0);
  rec(0, n, m, x, v, 0, ans);
  // vector<ll> v2(n,0);
  // rec(1,n,m,x,v2,0,ans);
  if (ans.size() == 0)
    cout << "-1";
  else
    cout << *min_element(ans.begin(), ans.end());

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

#include <algorithm>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 1LL << 60;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int n, m;
  ll x;
  int a[12][12];

  cin >> n >> m >> x;
  vector<ll> c(n);
  rep(i, n) {
    cin >> c[i];
    rep(j, m) { cin >> a[i][j]; }
  }
  ll ans = INF;
  rep(s, 1 << n) {
    ll 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: -11

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 1LL << 60;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int n, m;
  ll x;
  vector<ll> c;
  int a[12][12];

  cin >> n >> m >> x;
  rep(i, n) {
    cin >> c[i];
    rep(j, m) { cin >> a[i][j]; }
  }
  ll ans = INF;
  rep(s, 1 << n) {
    ll 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;
}
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
template <class T> bool chmax(T &a, const T &b) {
  if (b > a) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const long long INF = 2LL << 60;
using ll = long long;
using P = pair<ll, ll>;
ll n, m, x;
ll ans = INF;
vector<vector<ll>> a;
void dfs(vector<int> A) {
  if (A.size() < n) {
    A.push_back(1);
    dfs(A);
    A.erase(A.end() - 1);
    A.push_back(0);
    dfs(A);
    A.erase(A.end() - 1);
  }
  if (A.size() == n) {
    bool flg = true;
    ll price = 0;
    rep(i, n) { price += a[i][0] * A.at(i); }
    for (int j = 1; j < m + 1; j++) {
      ll cnt = 0;
      rep(i, n) { cnt += a[i][j] * A.at(i); }
      if (cnt < x) {
        flg = false;
        break;
      }
    }
    if (flg) {
      chmin(ans, price);
    }
  }
}
int main(int argc, char const *argv[]) {
  cin >> n >> m >> x;
  a = vector<vector<ll>>(n, vector<ll>(m + 1));
  rep(i, n) {
    rep(j, m + 1) { cin >> a[i][j]; }
  }
  dfs(vector<int>(0));
  if (ans == INF)
    ans = -1;
  cout << ans << endl;
  return 0;
}


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


Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
template <class T> bool chmax(T &a, const T &b) {
  if (b > a) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const long long INF = 2LL << 60;
using ll = long long;
using P = pair<ll, ll>;
ll n, m, x;
ll ans = INF;
vector<vector<ll>> a;
void dfs(vector<int> A) {
  if (A.size() < n) {
    A.push_back(1);
    dfs(A);
    A.erase(A.end() - 1);
    A.push_back(0);
    dfs(A);
    A.erase(A.end() - 1);
  }
  if (A.size() == n) {
    bool flg = true;
    ll price = 0;
    rep(i, n) { price += a.at(i).at(0) * A.at(i); }
    for (int j = 1; j < m + 1; j++) {
      ll cnt = 0;
      rep(i, n) { cnt += a.at(i).at(j) * A.at(i); }
      if (cnt < x) {
        flg = false;
        break;
      }
    }
    if (flg) {
      chmin(ans, price);
    }
  }
}
int main(int argc, char const *argv[]) {
  cin >> n >> m >> x;
  a = vector<vector<ll>>(n, vector<ll>(m));
  rep(i, n) {
    rep(j, m + 1) { cin >> a.at(i).at(j); }
  }
  dfs(vector<int>(0));
  if (ans == INF)
    ans = -1;
  cout << ans << endl;
  return 0;
}
Problem p02683 (C++) — buggy submission, verdict: 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;
}

Error: 0

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;
}