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

#include <math.h>

#include <algorithm>
#include <bitset>
#include <iostream>
#include <queue>
#include <sstream>
#include <vector>

using namespace std;

const int INF = 10000000;
typedef pair<int, int> P;

int main() {
  int N, M, X;
  cin >> N >> M >> X;
  vector<int> C(N);
  vector<vector<int>> A(N, vector<int>(M));
  // vector<vector<int>> test(N, vector<int>(M + 1));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M + 1; j++) {
      if (j == 0) {
        cin >> C[i];
      } else {
        cin >> A[i][j - 1];
      }
    }
  }

  int ans = INF;
  for (int i = 1; i <= (1 << N) - 1; i++) {
    bitset<12> use_flag(i);
    vector<int> sum_A(M, 0);
    int tmp_ans = 0;
    for (int j = 0; j < N; j++) {
      if (use_flag[j]) {
        for (int k = 0; k < M; k++) {
          sum_A[k] += A[j][k];
        }
        tmp_ans += C[j];
      }
    }

    bool pass_flag = true;
    for (int j = 0; j < M; j++) {
      if (sum_A[j] < X) {
        pass_flag = false;
        break;
      }
    }
    if (pass_flag) {
      ans = min(ans, tmp_ans);
    }
  }
  if (ans == INF) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <math.h>

#include <algorithm>
#include <bitset>
#include <iostream>
#include <queue>
#include <sstream>
#include <vector>

using namespace std;

const int INF = 100000000;
typedef pair<int, int> P;

int main() {
  int N, M, X;
  cin >> N >> M >> X;
  vector<int> C(N);
  vector<vector<int>> A(N, vector<int>(M));
  // vector<vector<int>> test(N, vector<int>(M + 1));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M + 1; j++) {
      if (j == 0) {
        cin >> C[i];
      } else {
        cin >> A[i][j - 1];
      }
    }
  }

  int ans = INF;
  for (int i = 1; i <= (1 << N - 1); i++) {
    bitset<12> use_flag(i);
    cout << use_flag << endl;
    vector<int> sum_A(M, 0);
    int tmp_ans = 0;
    for (int j = 0; j < N; j++) {
      cout << use_flag[j] << endl;
      if (use_flag[j]) {
        for (int k = 0; k < M; i++) {
          sum_A[k] += A[j][k];
        }
        tmp_ans += C[j];
      }
    }
    bool pass_flag = true;
    for (int j = 0; j < M; j++) {
      if (sum_A[j] < X) {
        pass_flag = false;
        break;
      }
    }
    if (pass_flag) {
      ans = min(ans, tmp_ans);
    }
  }
  if (ans == INF) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }

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

// ZA
#include <bits/stdc++.h>

#define o cout << "Hello did you expect this?" << endl;
#define ll long long
#define pb push_back
#define mp make_pair // with Z
#define F first
#define S second

using namespace std;

const int N = 6e6 + 100;
const int mod = 1e9 + 7;

void hey() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int a[100][100];
int c[100];
int pref[100];
int main() {
  hey();
  int n, m, x;
  cin >> n >> m >> x;
  for (int i = 1; i <= n; i++) {
    cin >> c[i];
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
    }
  }
  int ans = 1e9;
  for (int i = 0; i < (1 << n); i++) {
    int kol = 0;
    memset(pref, 0, sizeof pref);
    for (int k = 1; k <= n; k++) {
      if ((1 << (k - 1)) & i) {
        kol += c[k];
        for (int j = 1; j <= m; j++) {
          pref[j] += a[k][j];
        }
      }
    }
    bool bruh = 0;
    for (int j = 1; j <= m; j++) {
      if (pref[j] < x) {
        bruh = 1;
      }
    }
    if (!bruh) {
      ans = min(ans, kol);
    }
  }
  cout << (ans == 1e9 ? -1 : ans);
}


Error: TLE

Fixed submission:

// ZA
#include <bits/stdc++.h>

#define o cout << "Hello did you expect this?" << endl;
#define ll long long
#define pb push_back
#define mp make_pair // with Z
#define F first
#define S second

using namespace std;

const int N = 6e6 + 100;
const int mod = 1e9 + 7;

void hey() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int pref[100];
int c[100];
int used[100];
int n, m, x;
int a[100][100];
int ans = 1e9;
void rec(int kol) {
  int bruh = 0;
  for (int i = 1; i <= m; i++) {
    if (pref[i] < x) {
      bruh = 1;
    }
  }
  if (!bruh) {
    ans = min(ans, kol);
    return;
  }
  for (int i = 1; i <= n; i++) {
    if (!used[i]) {
      kol += c[i];
      used[i] = 1;
      for (int j = 1; j <= m; j++) {
        pref[j] += a[i][j];
      }
      rec(kol);
      used[i] = 0;
      kol -= c[i];
      for (int j = 1; j <= m; j++) {
        pref[j] -= a[i][j];
      }
    }
  }
}
int main() {
  hey();
  cin >> n >> m >> x;
  for (int i = 1; i <= n; i++) {
    cin >> c[i];
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
    }
  }
  rec(0);
  cout << (ans == 1e9 ? -1 : ans);
}
Problem p02683 (C++) — buggy submission, verdict: 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(m, 0);
  back(0, 0, mp, c, vals);
  if (fd == -1)
    ans = -1;
  cout << ans << endl;
  return 0;
}

Error: 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(n, 0);
  back(0, 0, mp, c, vals);
  if (fd == -1)
    ans = -1;
  cout << ans << endl;
  return 0;
}
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

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

int a[12][12];

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

  for (int j = 0; j < m; j++) {
    int sum = 0;
    for (int i = 0; i < n; i++) {
      sum += a[i][j];
    }
    if (sum < x) {
      cout << -1 << endl;
      return 0;
    }
  }

  for (int i = 0; i < pow(2, n); i++) {
    // iを2進数として見れば、各々の桁がboolとして使える
    bitset<12> tmp(i);
    vector<int> skills(m, 0);
    int sum = 0;
    bool isAchieve = true;
    for (int j = 0; j < n; j++) {
      if (tmp.test(j)) {
        sum += c[j];
        for (int k = 0; k < m; k++)
          skills[k] += a[j][k];
      }
    }
    for (auto v : skills) {
      if (v < x) {
        isAchieve = false;
        continue;
      }
    }
    if (isAchieve)
      ans = min(ans, sum);
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

void substractBooks(vector<int> &price, vector<vector<int>> &skills,
                    int &target, int &minPrice) {
  // ベースケース
  // 本を取り除いた結果、スキルの合計値が一つでも目標値を下回るなら、その前の数値を取って終了
  // 再帰部分
  // 本を1つ取り除いたら？
  vector<int> substractPrice = price;
  vector<vector<int>> substractSkills = skills;
  int sumPrice = 0;
  for (auto v : price)
    sumPrice += v;
  for (int i = 0; i < (int)skills.at(0).size(); i++) {
    int sum = 0;
    for (int j = 0; j < (int)skills.size(); j++) {
      sum += skills.at(j).at(i);
    }
    if (sum < target) {
      return;
    }
  }

  for (int i = 0; i < (int)skills.size(); i++) {
    substractPrice.erase(substractPrice.begin() + i);
    substractSkills.erase(substractSkills.begin() + i);
    minPrice = min(minPrice, sumPrice);
    substractBooks(substractPrice, substractSkills, target, minPrice);
    substractPrice = price;
    substractSkills = skills;
  }
}

int calcMinPrice(vector<int> &price, vector<vector<int>> &skills, int &target) {
  // ベースケース
  // 全てを足してもダメなら、-1を返す
  int sumPrice = 0;
  for (auto v : price)
    sumPrice += v;
  for (int i = 0; i < (int)skills.at(0).size(); i++) {
    int sum = 0;
    for (int j = 0; j < (int)skills.size(); j++) {
      sum += skills.at(j).at(i);
    }
    if (sum < target)
      return -1;
  }
  substractBooks(price, skills, target, sumPrice);
  return sumPrice;
}

int main() {
  int N, M, X;
  int ans = 0;
  cin >> N >> M >> X;
  vector<int> price(N);
  vector<vector<int>> skills(N, vector<int>(M));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M + 1; j++) {
      if (j == 0) {
        cin >> price.at(i);
        continue;
      }
      cin >> skills.at(i).at(j - 1);
    }
  }
  // 目標を達成できないのは、全ての本を買っても基準を満たさないスキルが存在する時
  // 再帰関数で全探索してみる？
  ans = calcMinPrice(price, skills, X);
  cout << ans << endl;
}
Problem p02683 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <climits>
#include <iostream>
using namespace std;

int N, M, X, C[15], A[15][15], S[15];

int rec(int n) {
  if (n == N) {
    int cost = 0, x[15];
    for (int i = 0; i < M; i++) {
      x[i] = 0;
    }
    for (int i = 0; i < N; i++) {
      if (S[i] == 1) {
        cost += C[i];
        for (int j = 0; j < M; j++) {
          x[j] += A[i][j];
        }
      }
    }
    for (int i = 0; i < M; i++) {
      if (x[i] < X)
        return INT_MAX;
    }
    return cost;
  }
  int minCost = INT_MAX;
  S[n] = 0;
  minCost = min(rec(n + 1), minCost);
  S[n] = 1;
  minCost = min(rec(n + 1), minCost);
  return minCost;
}

int main() {
  cin >> N >> M >> X;
  for (int i = 0; i < N; i++) {
    cin >> C[i];
    for (int j = 0; j < M; j++) {
      cin >> A[i][j];
    }
    S[i] = 0;
  }
  int cost = rec(0);
  if (cost == INT_MAX) {
    cout << -1 << endl;
    return 0;
  }
  cout << cost << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; (i) < (int)(n); i++)
using namespace std;

int N, M, X, C[15], A[15][15];

int calc(const vector<int> &v) {
  int S[15], cost = 0;
  rep(i, M) { S[i] = 0; }
  for (int x : v) {
    cost += C[x];
    bool clear = true;
    rep(i, M) {
      S[i] += A[x][i];
      if (S[i] < X)
        clear = false;
    }
    if (clear)
      return cost;
  };
  return INT_MAX;
}

int main() {
  cin >> N >> M >> X;
  vector<int> v;
  rep(i, N) {
    cin >> C[i];
    rep(j, M) { cin >> A[i][j]; }
    v.push_back(i);
  }
  int minCost = INT_MAX;
  do {
    minCost = min(calc(v), minCost);
  } while (next_permutation(v.begin(), v.end()));
  if (minCost == INT_MAX) {
    cout << -1 << endl;
    return 0;
  }
  cout << minCost << endl;
  return 0;
}
Problem p02683 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int a[12][12];

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

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, x, min = INT_MAX, tempSum;
  cin >> n >> m >> x;
  vector<int> c(n), num(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];
    }
  }
  for (int i = 0; i < n; i++)
    num[i] = i;

  do {
    tempSum = 0;
    vector<int> list(m, 0);
    for (int ii = 0; ii < n; ii++) {
      tempSum += c[num[ii]];
      for (int i = 0; i < m; i++) {
        list[i] += a[num[ii]][i];
      }
      int flg = 0;
      for (int j = 0; j < m; j++) {
        if (list[j] < x) {
          flg = 1;
        }
      }
      if (flg == 0) {
        if (min > tempSum) {
          min = tempSum;
        }
      }
    }
  } while (next_permutation(num.begin(), num.end()));
  if (min == INT_MAX) {
    cout << -1 << endl;
  } else {
    cout << min << endl;
  }
  return 0;
}
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;

const int C_MAX = 1200001;

int solve(int N, int M, int X, vector<int> C, vector<vector<int>> A) {
  vector<int> scores(M, 0);
  int min = C_MAX;

  for (int i = 0; i <= pow(2, N) - 1; i++) {
    int price = 0;   // priceの初期化
    bool flg = true; // scoresの各要素がX以上かどうかのフラッグ
    int b = i; // bの初期化(00000...00001(N桁) <= b <= 11111...11111(N桁))
    for (int j = 0; j < M; j++)
      scores[j] = 0; // scoresの各要素を0で初期化
    for (int j = 0; j < N;
         j++) { // bの桁のうち、1になっている桁の要素だけpriceとscoresに加算
      price += C[j] * (b % 2);
      // cout << "b is " << b << ". (b % " << 2 << ") is " << b % 2 << endl;
      for (int k = 0; k < M; k++)
        scores[k] += A[j][k] * (b % 2);
      b /= 2;
    }
    for (int j = 0; j < M; j++) {
      if (scores[j] < X) {
        flg = false;
        break;
      }
    }

    if (flg && min > price) {
      min = price;
      continue;
    }
  }
  if (min < C_MAX)
    return min;
  else
    return -1;
}

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

  cout << solve(N, M, X, C, A) << endl;

  return 0;
}

Error: 0

Fixed submission:

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

using namespace std;

const int C_MAX = 1200001;

int solve(int N, int M, int X, vector<int> C, vector<vector<int>> A) {
  vector<int> scores(M, 0);
  int min = C_MAX;

  for (int i = 0; i <= pow(2, M) - 2; i++) {
    int price = 0;   // priceの初期化
    bool flg = true; // scoresの各要素がX以上かどうかのフラッグ
    int b = i + 1;
    for (int j = 0; j < scores.size(); j++)
      scores[j] = 0; // scoresの各要素を0で初期化
    for (int j = 0; j < M;
         j++) { // bの桁のうち、1になっている桁の要素だけpriceとscoresに加算
      price += C[j] * (b % 2);

      for (int k = 0; k < M; k++)
        scores[k] += A[j][k] * (b % 2);
      b /= 2;
    }
    for (int j = 0; j < scores.size(); j++) {
      if (scores[j] < X) {
        flg = false;
        break;
      }
    }
    if (flg && min > price) {
      min = price;
      continue;
    }
  }
  if (min < C_MAX)
    return min;
  else
    return -1;
}

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

  cout << solve(N, M, X, C, A) << endl;

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

#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <iostream>  // cout, endl, cin
#include <math.h>    // sqrt
#include <string>    // string, to_string, stoi
#include <vector>    // vector
using namespace std;

int func(vector<vector<int>> &data, vector<bool> &bit, int ans, int N, int M,
         int X, int n) {
  if (n == 0) {
    int sum = 0;
    int know;
    bool check = true;
    for (int i = 1; i < M + 1; i++) {
      know = 0;
      for (int j = 0; j < N; j++) {
        if (bit.at(j)) {
          know += data.at(j).at(i);
        }
      }
      if (know < X) {
        check = false;
        break;
      }
    }
    if (check) {
      for (int i = 0; i < N; i++) {
        if (bit.at(i)) {
          sum += data.at(i).at(0);
        }
      }
      ans = min(ans, sum);
    }
    return ans;
  }
  int sumt, sumf;
  bit.at(N - n) = true;
  sumt = func(data, bit, ans, N, M, X, n - 1);
  bit.at(N - n) = false;
  sumf = func(data, bit, ans, N, M, X, n - 1);
  ans = min({ans, sumt, sumf});
  return ans;
}

int main() {
  int N, M, X;
  cin >> N >> M >> X;
  vector<vector<int>> data(N, vector<int>(M + 1));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M + 1; j++) {
      cin >> data.at(i).at(j);
    }
  }
  vector<bool> bit(N, false);
  int ans = 0;
  for (int i = 0; i < N; i++) {
    ans += data.at(i).at(0);
  }
  ans++;
  int money = func(data, bit, ans, N, M, X, N);
  if (money == ans) {
    money = -1;
  }
  cout << money << endl;
}

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>
using namespace std;

int comb(vector<vector<int>> &data, vector<int> &plus, int N, int n, int M,
         int X) {
  int sum;
  if (n == N) {
    for (int i = 0; i < M; i++) {
      bool finish = false;
      sum = 0;
      for (int j = 0; j < N; j++) {
        int know = 0;
        for (int c : plus) {
          if (c == 1) {
            know += data.at(c).at(N + 1);
          }
        }
        if (know < X) {
          finish = true;
          break;
        }
        if (j == N - 1) {
          for (int c : plus) {
            if (c == 1) {
              sum += data.at(c).at(0);
            }
          }
          return sum;
        }
      }
      if (finish) {
        return -1;
      }
    }
  }
  if (n < N) {
    plus.at(n + 1) = 0;
    int sum_0 = comb(data, plus, N, n + 1, M, X);
    plus.at(n + 1) = 1;
    int sum_1 = comb(data, plus, N, n + 1, M, X);
    int sum = max(sum_0, sum_1);
  }
  return sum;
}

int main() {
  int N, M, X;
  cin >> N >> M >> X;
  vector<vector<int>> data(N, vector<int>(M + 1));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M + 1; j++) {
      cin >> data.at(i).at(j);
    }
  }
  vector<int> plus(N, 0);
  int ans = comb(data, plus, N, 0, M, X);
  cout << ans << endl;
}
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

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

  vector<vector<int>> a(n, vector<int>(m));
  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];
  }
  long long ans = 12345678;
  int all = 1 << n;

  for (int bit = 0; bit < all; bit++) {
    long long cost = 0;
    vector<int> level(m);
    for (int i = 0; i < n; i++) {
      if ((bit >> i) & 1) {
        cost += c[i];
        for (int j = 0; j < m; j++) {
          level[j] += a[i][j];
        }
      }
    }
    bool ok = true;
    for (int j = 0; j < m; j++) {
      if (level[j] < x)
        ok = false;
    }
    if (ok)
      ans = min(ans, cost);
  }

  if (ans == 12345678)
    cout << -1;
  else
    cout << ans;

  return 0;
}


Error: -11

Fixed submission:

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

  vector<vector<int>> a(n, vector<int>(m));
  vector<int> c(n);

  for (int i = 1; i <= n; i++) {
    cin >> c[i];
    for (int j = 1; j <= m; j++)
      cin >> a[i][j];
  }
  int ans = 12345678;
  int all = 1 << n;

  for (int bit = 0; bit < all; bit++) {
    int cost = 0;
    vector<int> level(m);
    for (int i = 0; i < n; i++) {
      if (bit & (1 << i)) {
        cost += c[i];
        for (int j = 0; j < m; j++)
          level[j] += a[i][j];
      }
    }
    bool ok = true;
    for (int j = 0; j < m; j++) {
      if (level[j] < x)
        ok = false;
    }
    if (ok)
      ans = min(ans, cost);
  }

  if (ans == 12345678)
    cout << -1;
  else
    cout << ans;

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

#include <bits/stdc++.h>
using namespace std;
#define Fast_IO                                                                \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
int n, m, x;
int ans = INT_MAX;
int flag = 0;
int dp[1000000];
void recur(int mask, vector<vector<int>> &algo, vector<int> &cost, int curr,
           vector<int> &stack) {
  if (dp[mask])
    return;
  vector<int> check(m, 0);
  if (stack == check) {
    ans = min(ans, curr);
    flag = 1;
  }
  for (int i = 0; i < n; i++) {
    // cout<<(mask&(1<<i))<<" "<<(1<<i)<<"\\n";
    if ((mask & (1 << i)) == 0) {
      vector<int> cp(m, 0);
      // cout<<"fff"<<"\\n";
      for (int j = 0; j < m; j++) {
        cp[j] = stack[j];
        stack[j] = max(0, stack[j] - algo[i][j]);
      }
      recur(mask | (1 << i), algo, cost, curr + cost[i], stack);
      stack = cp;
    }
  }
  dp[mask] = 1;
}
int main() {
  memset(dp, 0, sizeof(dp));
  cin >> n >> m >> x;
  vector<int> cost(n, 0);
  vector<vector<int>> algo(n, vector<int>(m, 0));
  vector<int> z(m, x);
  for (int i = 0; i < n; i++) {
    cin >> cost[i];
    for (int j = 0; j < m; j++) {
      cin >> algo[i][j];
    }
  }
  recur(0, algo, cost, 0, z);
  if (flag)
    cout << ans << "\\n";
  else
    cout << -1 << "\\n";
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define Fast_IO                                                                \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
int n, m, x;
int ans = INT_MAX;
int flag = 0;
void recur(int mask, vector<vector<int>> &algo, vector<int> &cost, int curr,
           vector<int> &stack) {
  vector<int> check(m, 0);
  // cout<<mask<<"\\n";
  // for(auto i:stack)cout<<i<<" ";
  // cout<<"\\n";
  if (stack == check) {
    ans = min(ans, curr);
    flag = 1;
  }
  for (int i = 0; i < n; i++) {
    // cout<<(mask&(1<<i))<<" "<<(1<<i)<<"\\n";
    if ((mask & (1 << i)) == 0) {
      vector<int> cp(m, 0);
      // cout<<"fff"<<"\\n";
      for (int j = 0; j < m; j++) {
        cp[j] = stack[j];
        stack[j] = max(0, stack[j] - algo[i][j]);
      }
      recur(mask | (1 << i), algo, cost, curr + cost[i], stack);
      stack = cp;
    }
  }
}
int main() {
  cin >> n >> m >> x;
  vector<int> cost(n, 0);
  vector<vector<int>> algo(n, vector<int>(m, 0));
  vector<int> z(m, x);
  for (int i = 0; i < n; i++) {
    cin >> cost[i];
    for (int j = 0; j < m; j++) {
      cin >> algo[i][j];
    }
  }
  recur(0, algo, cost, 0, z);
  if (flag)
    cout << ans << "\\n";
  else
    cout << -1 << "\\n";
}