alexjercan/bugnet huggingface dataset:
Problem p02683 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iomanip> //cout << fixed << setprecision() <<
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
vector<vector<int>> v; // 入力値
ll mint = 10000000000;
int c = 0;

void monmo(int y, int n, int m, int x, vector<vector<int>> vv) {
  vector<int> ten;
  int flag1 = 0;
  for (int i = 0; i < m + 1; i++) {
    ten.push_back(0);
    ten[i] += vv[y][i];
  } // flag1がたつと次の再帰に行く
  for (int i = 0; i < m; i++) {
    if (ten[i + 1] < x)
      flag1 = 1;
  }

  if (y >= n) {
    // 処理なし
  } else {

    if (flag1 == 1) {
      for (int i = y; i < n - 1; i++) {
        vector<vector<int>> v2;
        v2 = vv;
        for (int j = 0; j < m + 1; j++) {
          v2[i + 1][j] += vv[y][j];
        }
        monmo(i + 1, n, m, x, v2);
      }
    } else {
      if (mint > ten[0])
        mint = ten[0];
      c++;
    }
  }
}

int main() {
  int n, m, x, num;
  cin >> n >> m >> x;
  for (int i = 0; i < n; i++) {
    v.emplace_back();
    for (int j = 0; j < m + 1; j++) {
      cin >> num;
      v[i].push_back(num);
    }
  }
  for (int i = 0; i < n; i++) {
    monmo(i, n, m, x, v);
  }
  if (c == 0)
    mint = -1;
  cout << mint;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iomanip> //cout << fixed << setprecision() <<
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
ll mint = 10000000000;
int co = 0;

void monmo(int n, int m, int x, int f, vector<vector<int>> v) {
  vector<int> ten;
  int flag1 = 0;
  for (int i = 0; i < m + 1; i++) {
    ten.push_back(0);
  }
  if (n == 0) {
    // 処理なし
  } else {
    if (f > 0) {
      for (int i = 0; i < n + 1; i++) {
        vector<vector<int>> v2;
        v2 = v;
        for (int j = 0; j < m + 1; j++) {
          v2[i][j] = v[n][j];
        }
        monmo(n, m, x, 0, v2);
      }

    } else {
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < m + 1; j++) {
          ten[j] += v[i][j];
        }
      }
      for (int i = 0; i < m; i++) {
        if (ten[i + 1] < x)
          flag1 = 1; // 条件を満たさない
      }
      if (flag1 == 1) {
        // 処理なし
      } else {
        // 条件を満たす
        if (mint > ten[0])
          mint = ten[0];
        monmo(n - 1, m, x, 1, v);
        co++;
      }
    }
  }
}

int main() {
  int n, m, x, num;
  vector<vector<int>> v;
  cin >> n >> m >> x;
  for (int i = 0; i < n; i++) {
    v.emplace_back();
    for (int j = 0; j < m + 1; j++) {
      cin >> num;
      v[i].push_back(num);
    }
  }
  monmo(n, m, x, 0, v);
  if (co == 0)
    mint = -1;
  cout << mint;
}
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

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

int gcd(int x, int y) {
  if (x < y)
    swap(x, y);
  int r = x % y;
  if (r == 0) {
    return y;
  }
  return gcd(y, r);
}

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];
    }
  }
  ll minSumC = 1e9;
  bool bigFlag = false;
  for (int tmp = 0; tmp < (1 << N); tmp++) {
    bitset<12> book(tmp);
    vector<ll> know(M);
    ll sumC = 0;
    bool flag = true;
    for (int i = 0; i < N; i++) {
      if (book.test(i)) {
        sumC += C[i];
        for (int j = 0; j < M; j++) {
          know[j] += A[i][j];
        }
      }
    }
    for (int j = 0; j < M; j++) {
      if (know[j] < X) {
        flag = false;
        break;
      }
    }
    if (flag) {
      minSumC = min(minSumC, sumC);
      bigFlag = true;
    }
  }
  if (bigFlag) {
    cout << minSumC << endl;
  } else {
    cout << -1 << endl;
  }
}

Error: 0

Fixed submission:

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

int gcd(int x, int y) {
  if (x < y)
    swap(x, y);
  int r = x % y;
  if (r == 0) {
    return y;
  }
  return gcd(y, r);
}

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];
    }
  }
  ll minSumC = 1e9;
  bool bigFlag = false;
  for (int tmp = 0; tmp < (1 << N); tmp++) {
    bitset<12> book(tmp);
    vector<ll> know(N);
    ll sumC = 0;
    bool flag = true;
    for (int i = 0; i < N; i++) {
      if (book.test(i)) {
        sumC += C[i];
        for (int j = 0; j < M; j++) {
          know[j] += A[i][j];
        }
      }
    }
    for (int j = 0; j < M; j++) {
      if (know[j] < X) {
        flag = false;
        break;
      }
    }
    if (flag) {
      minSumC = min(minSumC, sumC);
      bigFlag = true;
    }
  }
  if (bigFlag) {
    cout << minSumC << endl;
  } else {
    cout << -1 << endl;
  }
}
Problem p02683 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define MAX 12000000

int research_book(int N, int M, int X, vector<int> C, vector<vector<int>> A) {
  int ans = MAX;
  rep(s, 1 << N) {
    vector<int> S(M);
    int cost = 0;
    rep(i, N) {
      if (s >> i & 1) {
        cost += C[i];
        rep(j, M) S[j] += A[i][j];
      }
    }
    bool ok = true;
    rep(j, M) if (S[j] < X) ok = false;
    if (ok)
      ans = min(ans, cost);
  }
  return ans;
}

int main() {
  int N, M, X;

  cin >> N >> M >> X;

  vector<int> C(N);
  vector<vector<int>> A(N, vector<int>(M, 0));

  int Finalans = -1;

  rep(i, N) {
    cin >> C[i];
    rep(j, M) cin >> A[i][j];
  }

  int ans;
  ans = research_book(N, M, X, C, A);

  if (ans == MAX) {
    cout << -1;
  } else {
    cout << ans;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int research_book(int book, int i, int N, int M, int X, vector<int> &select,
                  vector<vector<int>> C, vector<int> &S) {
  int ans = -1, result, countS = 0;
  if (book == 0) {
    for (int k = 1; k < M + 1; k++) {
      if (S[k] >= X) {
        countS++;
      }
    }
    if (countS == M) {
      return C[i][0];
    } else {
      return -1;
    }
  } else {
    for (int k = 0; k < N; k++) {
      if (count(select.begin(), select.end(), k) == 0) {
        select.push_back(k);
        for (int j = 0; j < M + 1; j++) {
          S[j] += C[k][j];
        }
        result = research_book(book - 1, k, N, M, X, select, C, S);
        select.pop_back();
        for (int j = 0; j < M + 1; j++) {
          S[j] -= C[k][j];
        }
        if ((result != -1 && ans > result) || ans == -1) {
          ans = result;
        }
      }
    }
    if (ans != -1 && i != -1) {
      return ans + C[i][0];
    } else {
      return ans;
    }
  }
}

int main() {
  int N, M, X;

  cin >> N >> M >> X;

  vector<vector<int>> C(N, vector<int>(M + 1, 0));
  vector<int> S(M + 1);
  int Finalans = -1;

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

  int ans = 0;
  for (int i = 1; i < M + 1; i++) {
    if (S[i] >= X) {
      ans++;
    }
  }
  vector<int> S2(M + 1, 0);
  if (ans == M) {
    ans = 0;
    vector<int> select;
    for (int i = 1; i <= N; i++) {
      ans = research_book(i, -1, N, M, X, select, C, S2);
      if (ans != -1) {
        if (Finalans > ans || Finalans == -1)
          Finalans = ans;
      }
    }
    cout << Finalans;

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

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

bool provera(vector<long long> &niz, int &m, long long &x) {
  for (int i = 0; i < m; i++)
    if (niz[i] < x)
      return false;
  return true;
}

long long f(vector<vector<long long>> &v, vector<long long> &cene, int &n,
            int &m, long long &x, vector<long long> niz, int index,
            long long cena) {
  if (index == n) {
    if (provera(niz, m, x))
      return cena;
    else
      return LLONG_MAX;
  }
  long long m1, m2;
  m1 = f(v, cene, n, m, x, niz, index + 1, cena);
  for (int i = 0; i < m; i++)
    niz[i] += v[index][i];
  cena += cene[index];
  m2 = f(v, cene, n, m, x, niz, index + 1, cena);
  return min(m1, m2);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  long long x, resenje;
  cin >> n >> m >> x;
  vector<long long> cena(n);
  vector<vector<long long>> v(n, vector<long long>(m));
  for (int i = 0; i < n; i++) {
    cin >> cena[i];
    for (int j = 0; j < m; j++)
      cin >> v[i][j];
  }
  vector<long long> niz(m, 0);
  resenje = f(v, cena, n, m, x, niz, 0, 0);
  if (resenje == LLONG_MAX)
    cout << -1;
  else
    cout << resenje;
}


Error: WA

Fixed submission:

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

bool provera(vector<long long> &niz, int &m, long long &x) {
  for (int i = 0; i < m; i++)
    if (niz[i] < x)
      return false;
  return true;
}

long long f(vector<vector<long long>> &v, vector<long long> &cene, int &n,
            int &m, long long &x, vector<long long> niz, int index,
            long long cena) {
  if (index == n) {
    if (provera(niz, m, x))
      return cena;
    else
      return LLONG_MAX;
  }
  long long m1, m2;
  m1 = f(v, cene, n, m, x, niz, index + 1, cena);
  for (int i = 0; i < m; i++)
    niz[i] += v[index][i];
  cena += cene[index];
  m2 = f(v, cene, n, m, x, niz, index + 1, cena);
  return min(m1, m2);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  long long x, resenje;
  cin >> n >> m >> x;
  vector<long long> cena(n);
  vector<vector<long long>> v(n, vector<long long>(m));
  for (int i = 0; i < n; i++) {
    cin >> cena[i];
    for (int j = 0; j < m; j++)
      cin >> v[i][j];
  }
  vector<long long> niz(n, 0);
  resenje = f(v, cena, n, m, x, niz, 0, 0);
  if (resenje == LLONG_MAX)
    cout << -1;
  else
    cout << resenje;
}
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)
#define ll long long
const ll INF = 1e9;
int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> c(n);
  vector<vector<int>> a(n, vector<int>(m));
  rep(i, n) {
    cin >> c[i];
    rep(j, m) cin >> a[i][j];
  }
  bool ok = false;

  ll ans = INF;
  for (int bit = 0; bit < (1 << n); ++bit) {
    ll coin = 0;
    vector<ll> res(m, 0);
    rep(i, n) {
      if (bit & (1 << i)) {
        coin += c[i];
        rep(j, m) res[j] += a[i][j];
      }
    }
    bool yes = true;
    rep(i, m) {
      if (res[i] < x) {
        yes = false;
        break;
      }
    }
    if (yes) {
      ans = min(ans, coin);
      ok = true;
    }
    rep(i, m) res[i] = 0;
  }
  if (ok)
    cout << ans << endl;
  else
    cout << -1 << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define ll long long
const ll INF = 1e9;
int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> c(n);
  vector<vector<int>> a(n, vector<int>(m));
  rep(i, n) {
    cin >> c[i];
    rep(j, m) cin >> a[i][j];
  }
  bool ok = false;

  ll ans = INF;
  for (int bit = 0; bit < (1 << n); ++bit) {
    ll coin = 0;
    vector<ll> res(n);
    rep(i, n) {
      if (bit & (1 << i)) {
        coin += c[i];
        rep(j, m) res[j] += a[i][j];
      }
    }
    rep(i, m) {
      if (res[i] < x)
        break;
      ans = min(ans, coin);
      ok = true;
    }
    rep(i, m) res[i] = 0;
  }
  if (ok)
    cout << ans << endl;
  else
    cout << -1 << endl;
}
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

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

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

  int min_cost = 1200010;
  bool ch = false;
  for (int tmp = 0; tmp < (1 << n); tmp++) { // 全探索
    bitset<12> b(tmp);
    int tmp_cost = 0;
    vector<int> tmp_avi(m, 0);
    // 金額と、能力上昇値の計算始まり
    rep(i, n) {
      if (b.test(i)) {
        tmp_cost += c[i];
        rep(j, m) { tmp_avi[j] += avi[i][j]; }
      }
    }
    // 金額と、能力上昇値の計算終わり
    bool suc = true;
    rep(i, m) {
      if (tmp_avi[i] < x) {
        suc = false;
      }
    }
    if (suc) {
      min_cost = min(min_cost, tmp_cost);
      ch = true;
    }
  }

  if (ch) {
    cout << min_cost << endl;
  } else {
    cout << -1 << endl;
  }
}

Error: 0

Fixed submission:

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

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

  int min_cost = 1200010;
  bool ch = false;
  for (int tmp = 0; tmp < (1 << n); tmp++) {
    bitset<12> b(tmp);
    int tmp_cost = 0;
    vector<int> tmp_avi(m, 0);
    rep(i, n) {
      if (b.test(i)) {
        tmp_cost += c.at(i);
        rep(j, m) { tmp_avi.at(j) += avi.at(i).at(j); }
      }
    }
    bool suc = true;
    rep(i, n) {
      if (tmp_avi.at(i) < x) {
        suc = false;
      }
    }
    if (suc) {
      min_cost = min(min_cost, tmp_cost);
      ch = true;
    }
  }

  if (ch) {
    cout << min_cost << endl;
  } else {
    cout << -1 << endl;
  }
}
Problem p02683 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 922337203685477;
const ll mininf = -922337203685477;
const ll nax = 0;

ll n, m, k, a[15][15], c[15], val[15], ans = inf;

void kombinasi(ll nilai, ll x) {
  if (nilai > ans) {
    return;
  }
  bool bl = 1;
  for (ll i = 0; i < m; i++) {
    if (val[i] < k) {
      bl = 0;
    }
  }
  if (bl) {
    ans = min(nilai, ans);
  }
  for (ll i = x; i < n; i++) {
    for (ll j = 0; j < m; j++) {
      val[j] += a[i][j];
    }
    kombinasi(nilai + c[i], i + 1);
    for (ll j = 0; j < m; j++) {
      val[j] -= a[i][j];
    }
  }
}

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

  cin >> n >> m >> k;
  for (ll i = 0; i < n; i++) {
    cin >> c[i];
    for (ll j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  kombinasi(0, 0);
  if (ans == inf) {
    ans = -1;
  }
  cout << ans << '\\n';
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 922337203685477;
const ll mininf = -922337203685477;
const ll nax = 0;

ll n, m, k, a[15][15], c[15], val[15], ans = inf;

void kombinasi(ll nilai, ll x) {
  bool bl = 1;
  for (ll i = 0; i < m; i++) {
    if (val[i] < k) {
      bl = 0;
    }
  }
  if (bl) {
    ans = min(nilai, ans);
  }
  for (ll i = x; i < n; i++) {
    for (ll j = 0; j < m; j++) {
      val[j] += a[i][j];
    }
    kombinasi(nilai + c[i], x + 1);
    for (ll j = 0; j < m; j++) {
      val[j] -= a[i][j];
    }
  }
}

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

  cin >> n >> m >> k;
  for (ll i = 0; i < n; i++) {
    cin >> c[i];
    for (ll j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  kombinasi(0, 0);
  if (ans == inf) {
    ans = -1;
  }
  cout << ans << '\\n';
}
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template <typename T> vector<T> make_v(size_t a, T b) {
  return vector<T>(a, b);
}

template <typename... Ts> auto make_v(size_t a, Ts... ts) {
  return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

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

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

  int ans = numeric_limits<int>::max();
  rep(b, (1 << n)) {
    int t = 0;
    vector<int> now(m, 0);
    rep(i, n) {
      if (b & (1 << i)) {
        t += c[i];
        rep(j, m) { now[j] += a[i][j]; }
      }
    }
    bool f = all_of(now.begin(), now.end(), [&](int v) { return v >= x; });

    if (f)
      ans = min(ans, t);
  }

  if (ans == numeric_limits<int>::max())
    ans = -1;
  cout << ans << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template <typename T> vector<T> make_v(size_t a, T b) {
  return vector<T>(a, b);
}

template <typename... Ts> auto make_v(size_t a, Ts... ts) {
  return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

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

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

  int ans = numeric_limits<int>::max();
  rep(b, (1 << n)) {
    int t = 0;
    vector<int> now(m, 0);
    rep(i, n) {
      if (b & (1 << i)) {
        t += c[i];
        rep(j, n) { now[j] += a[i][j]; }
      }
    }
    bool f = all_of(now.begin(), now.end(), [&](int v) { return v >= x; });

    if (f)
      ans = min(ans, t);
  }

  if (ans == numeric_limits<int>::max())
    ans = -1;
  cout << ans << endl;

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

#include <bits/stdc++.h>
#define two(a) (1 << (a))
#define LINF (1ll << 61)
#define EPS (1e-14)
#define Lshift(a, b) ((a) << (b))
#define Rshift(a, b) ((a) >> (b))
#define rep(a, b) for (a = 0; a < b; a++)
#define xrep(a, b, c) for (a = b; a < c; a++)
#define INF (1 << 29)
#define sz(a) int(a.size())
#define mset(x) memset(x, 0, sizeof(x))
#define swap(a, b) ((a ^= b), (b ^= a), (a ^= b))
#define GET(x) (mark[x >> 5] >> (x & 31) & 1)
#define SET(x) (mark[x >> 5] |= 1 << (x & 31))
#define maxL (10000000 >> 5) + 1
#define mod 1000000007
#define vi vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define si set<int>
#define pb push_back
typedef long long ll;
using namespace std;

int c[13];
int in[13][13];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n, m, x;
  cin >> n >> m >> x;
  int i, j;
  rep(i, n) {
    cin >> c[i];
    rep(j, m) { cin >> in[i][j]; }
  }
  ll s[m], k;
  ll ans(LINF);
  rep(i, two(n)) {
    ll t(0);
    memset(s, 0, sizeof(s));
    rep(j, n) {
      int tj = two(j);
      if (tj & i) {
        t += c[j];
        rep(k, m) s[k] += in[j][k];
      }
    }
    rep(j, m) {
      if (s[j] < x)
        break;
    }
    if (j == m) {
      ans = min(ans, t);
    }
  }
  if (ans == LINF)
    ans = -1;
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define two(a) (1 << (a))
#define LINF (1ll << 61)
#define EPS (1e-14)
#define Lshift(a, b) ((a) << (b))
#define Rshift(a, b) ((a) >> (b))
#define rep(a, b) for (a = 0; a < b; a++)
#define xrep(a, b, c) for (a = b; a < c; a++)
#define INF (1 << 29)
#define sz(a) int(a.size())
#define mset(x) memset(x, 0, sizeof(x))
#define swap(a, b) ((a ^= b), (b ^= a), (a ^= b))
#define GET(x) (mark[x >> 5] >> (x & 31) & 1)
#define SET(x) (mark[x >> 5] |= 1 << (x & 31))
#define maxL (10000000 >> 5) + 1
#define mod 1000000007
#define vi vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define si set<int>
#define pb push_back
typedef long long ll;
using namespace std;

int c[13];
int in[13][13];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n, m, x;
  cin >> n >> m >> x;
  int i, j;
  rep(i, n) {
    cin >> c[i];
    rep(j, m) { cin >> in[i][j]; }
  }
  ll s[n], k;
  ll ans(LINF);
  rep(i, two(n)) {
    ll t(0);
    memset(s, 0, sizeof(s));
    rep(j, n) {
      int tj = two(j);
      if (tj & i) {
        t += c[j];
        rep(k, m) s[k] += in[j][k];
      }
    }
    rep(j, m) {
      if (s[j] < x)
        break;
    }
    if (j == m) {
      ans = min(ans, t);
    }
  }
  if (ans == LINF)
    ans = -1;
  cout << ans << endl;
}
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

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

ll min_cost = 1200001;
ll n, m, x;
vector<vector<ll>> a(14, vector<ll>(14));
vector<ll> c(14);
vector<ll> kara(14);

void dfs(int len, ll cost, vector<ll> skill) {
  if (len > n) {
    bool ok = true;
    rep(i, m) if (skill.at(i) < x) ok = false;
    if (ok)
      min_cost = min(min_cost, cost);
  } else {
    dfs(len + 1, cost, skill);
    rep(i, m) skill.at(i) += a.at(len).at(i);
    dfs(len + 1, cost + c.at(len), skill);
  }
}

int main() {

  cin >> n >> m >> x;

  rep(i, n) {
    cin >> c.at(i);
    rep(j, m) cin >> a.at(i).at(j);
  }
  dfs(0, 0, kara);
  if (min_cost == 1200001)
    cout << -1 << endl;
  else
    cout << min_cost << endl;
}

Error: 0

Fixed submission:

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

ll min_cost = 1200001;
ll n, m, x;
vector<vector<ll>> a(12, vector<ll>(12));
vector<ll> c(12);
vector<ll> kara(12);

void dfs(int len, ll cost, vector<ll> skill) {
  if (len >= n + 1) {
    bool ok = true;
    rep(i, m) if (skill.at(i) < x) ok = false;
    if (ok)
      min_cost = min(min_cost, cost);
  } else {
    dfs(len + 1, cost, skill);
    rep(i, m) skill.at(i) += a.at(len).at(i);
    dfs(len + 1, cost + c.at(len), skill);
  }
}

int main() {

  cin >> n >> m >> x;

  rep(i, n) {
    cin >> c.at(i);
    rep(j, m) cin >> a.at(i).at(j);
  }
  dfs(0, 0, kara);
  if (min_cost == 1200001)
    cout << -1 << endl;
  else
    cout << min_cost << endl;
}