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

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

const int INF = 1e9;
int n, m, x;
int c[15], a[15][15];
int algo[15];
int ans = INF, cost;

bool ok() {
  for (int i = 0; i < m; i++)
    if (algo[i] < x)
      return false;
  return true;
}

void dfs(int i) {
  if (i == n) {
    if (ok())
      ans = min(ans, cost);
    return;
  }
  cost += c[i];
  for (int j = 0; j < m; j++)
    algo[j] += a[i][j];
  dfs(i + 1);
  cost -= c[i];
  for (int j = 0; j < m; j++)
    algo[j] -= a[i][j];
  dfs(i + 1);
}

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];
  }
  dfs(0);
  cout << (ans == INF ? -1 : ans);
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

const int N = 15;
typedef long long ll;

int book[N]; // 书的价格
int w[N][N];
bool st[N];
int v[N]; // 用于记录每个算法的累加值
int n, m, x;
int minmon = 0x3f3f3f3f;
int summon = 0;

void dfs(int u) // u记录已经有几本书在列
{
  if (u == n)
    return; // 应该走完所有路径才能找到最优解,u是从开始的
  else {
    for (int i = 0; i < n; i++)
      if (!st[i]) {
        for (int j = 0; j < m; j++)
          v[j] += w[i][j];
        summon += book[i];
        int flag = 1;
        for (int j = 0; j < m; j++)
          if (v[j] < x)
            flag = 0;
        if (flag) {
          if (summon < minmon)
            minmon = summon;
          //					return;
        }
        st[i] = 1;
        dfs(u + 1);
        for (int j = 0; j < m; j++)
          v[j] -= w[i][j];
        summon -= book[i];
        st[i] = 0;
        dfs(u + 1);
      }
  }
  return;
}

int main() {
  //	freopen("input.txt","r",stdin);

  scanf("%d%d%d", &n, &m, &x);
  for (int i = 0; i < n; i++) {
    scanf("%d", &book[i]);
    for (int j = 0; j < m; j++)
      scanf("%d", &w[i][j]);
  }
  dfs(0);
  if (minmon == 0x3f3f3f3f)
    printf("-1");
  else
    printf("%d", minmon);

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

#include <bits/stdc++.h>
#include <iostream>
typedef long long ll;
#define rep(i, a, b) for (ll i = a; i <= b; i++)
#define per(i, a, b) for (ll i = a; i >= b; i--)
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

vi C, X;
vvi A;
int n, m, x;

int findMinCost(int index) {
  // cout<<index<<"\\n";
  bool flag = true;
  rep(i, 0, m - 1) {
    if (X[i] > 0) {
      flag = false;
      break;
    }
  }
  if (flag) {
    return 0;
  }

  if (index > n - 1)
    return INT_MAX;

  rep(i, 0, m - 1) { X[i] -= A[index][i]; }
  int min_cost = findMinCost(index + 1);
  if (min_cost != INT_MAX)
    min_cost += C[index];
  rep(i, 0, m - 1) { X[i] += A[index][i]; }

  return min(min_cost, findMinCost(index + 1));
}

int main(int argc, char const *argv[]) {
  // ifstream cin("input.txt");

  cin >> n >> m >> x;
  C = vi(n);
  A = vvi(n, vi(m));

  rep(i, 0, n - 1) {
    cin >> C[i];
    rep(j, 0, m - 1) cin >> A[i][j];
  }

  X = vi(m, x);
  int min = findMinCost(0);
  if (min == INT_MAX)
    cout << -1;
  else
    cout << min;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#include <iostream>
typedef long long ll;
#define rep(i, a, b) for (ll i = a; i <= b; i++)
#define per(i, a, b) for (ll i = a; i >= b; i--)
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

vi C, X;
vvi A;
int n, m, x;

int findMinCost(int index) {
  // cout<<index<<"\\n";
  bool flag = true;
  rep(i, 0, m - 1) {
    if (X[i] > 0) {
      flag = false;
      break;
    }
  }
  if (flag) {
    return 0;
  }

  if (index > n - 1)
    return INT_MAX;

  rep(i, 0, n - 1) { X[i] -= A[index][i]; }
  int min_cost = findMinCost(index + 1);
  if (min_cost != INT_MAX)
    min_cost += C[index];
  rep(i, 0, n - 1) { X[i] += A[index][i]; }
  return min(min_cost, findMinCost(index + 1));
}

int main(int argc, char const *argv[]) {
  // ifstream cin("input.txt");

  cin >> n >> m >> x;
  C = vi(n);
  A = vvi(n, vi(m));

  rep(i, 0, n - 1) {
    cin >> C[i];
    rep(j, 0, m - 1) cin >> A[i][j];
  }

  X = vi(m, x);
  int min = findMinCost(0);
  if (min == INT_MAX)
    cout << -1;
  else
    cout << min;
}
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

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

ll mincost = INT_MAX;
void func(int idx, vector<ll> &c, vector<vector<ll>> &a, vector<ll> cost_ar,
          ll cost, ll n, ll m, ll x) {
  if (idx == n) {
    bool flag = true;
    for (auto a : cost_ar) {
      if (a < x) {
        flag = false;
        break;
      }
    }
    if (flag) {
      mincost = min(mincost, cost);
      return;
    }
    return;
  }
  // Not choose
  func(idx + 1, c, a, cost_ar, cost, n, m, x);

  // Choose
  cost += c[idx];
  for (ll i = 0; i < m; i++) {
    cost_ar[i] += a[idx][i];
  }
  func(idx + 1, c, a, cost_ar, cost, n, m, x);
}

int main() {
  // your code goes here
  ll n, m, x;
  cin >> n >> m >> x;
  vector<ll> c(n);
  vector<vector<ll>> a(n, vector<ll>(m));
  for (ll i = 0; i < n; i++) {
    cin >> c[i];
    for (ll j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  vector<ll> cost_ar(m, 0);
  func(0, c, a, cost_ar, 0, n, m, x);
  if (mincost == INT_MAX)
    mincost = -1;
  cout << mincost << endl;

  return 0;
}

Error: -6
terminate called after throwing an instance of 'std::length_error'
  what():  cannot create std::vector larger than max_size()


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef int lo;
typedef vector<lo> vl;
typedef vector<vl> vll;
#define all(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " = " << x << endl;
#define REPV(a, b, c) for (lo(a) = b; (a) < (c); (a)++)
#define REP(a, b) for (lo i = (a); i < (b); i++)

template <typename T>

istream &operator>>(istream &in, vector<T> &v) {
  for (unsigned i = 0; i < v.size(); i++)
    in >> v[i];
  return in;
}

bool compare(vl &under_std, lo X) {
  REP(0, under_std.size()) {
    if (under_std[i] < X)
      return false;
  }
  return true;
}

long long solve(vll &u_std, vl &cost, vl &under_std, lo money, lo N, lo X) {
  if (compare(under_std, X))
    return money;
  if (N == 0)
    return LLONG_MAX;
  vl a(under_std.size(), 0);
  REP(0, under_std.size()) { a[i] = u_std[N - 1][i] + under_std[i]; }
  long long money1 = solve(u_std, cost, a, money + cost[N - 1], N - 1, X);
  long long money2 = solve(u_std, cost, under_std, money, N - 1, X);
  return min(money1, money2);
}
void solve1() {

  lo N, M, X, c;
  vl cost(N);
  vll u_std;
  cin >> N >> M >> X;
  for (lo i = 0; i < N; i++) {
    cin >> c;
    cost.push_back(c);
    vl temp;
    for (lo j = 0; j < M; j++) {
      cin >> c;
      temp.push_back(c);
    }
    u_std.push_back(temp);
    temp.clear();
  }
  vl under_std(M, 0);
  lo money = 0;

  long long ans = solve(u_std, cost, under_std, money, N, X);
  if (ans == LLONG_MAX)
    cout << "-1" << endl;
  else
    cout << ans << endl;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout.precision(20);
  solve1();
  return 0;
}
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
vector<int> c, d;
vector<vector<int>> a;
int n, m, x, sum = 0, res = 1200001;
int search(int cnt) {
  if (cnt >= n) {
    bool solve = true;
    --cnt;
    for (int i = 0; i < m; ++i)
      solve &= (d[i] >= x);
    if (solve == true)
      return sum;
    else
      return res;
  }
  for (int i = 0; i < 2; ++i) {
    if (i == 1) {
      sum += c[cnt];
      for (int j = 0; j < m; ++j)
        d[j] += a[cnt][j];
    }
    res = min(res, search(cnt + 1));
  }
  for (int i = 0; i < m; ++i)
    d[i] -= a[cnt][i];
  sum -= c[cnt];
  if (cnt == 0 && res == 1200001)
    return -1;
  else
    return res;
}

int main(void) {
  cin >> n >> m >> x;
  c.resize(n);
  d.resize(m);
  a.resize(n);
  for (int i = 0; i < n; ++i)
    a[i].resize(m);
  for (int i = 0; i < n; ++i) {
    cin >> c[i];
    for (int j = 0; j < m; ++j)
      cin >> a[i][j];
  }
  cout << search(0) << endl;
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
vector<int> c, d;
vector<vector<int>> a;
int n, m, x, sum = 0, res = 1200001;
int search(int cnt) {
  if (cnt >= n) {
    bool solve = true;
    --cnt;
    //    for(int i=0; i<m; ++i) solve&=(d[i]>=x);
    if (solve == true)
      return sum;
    else
      return res;
  }
  for (int i = 0; i < 2; ++i) {
    if (i == 1) {
      sum += c[cnt];
      for (int j = 0; j < m; ++j)
        d[j] += a[cnt][j];
    }
    res = min(res, search(cnt + 1));
  }
  for (int i = 0; i < m; ++i)
    d[i] -= a[cnt][i];
  sum -= c[cnt];
  if (cnt == 0 && res == 1200001)
    return -1;
  else
    return res;
}

int main(void) {
  cin >> n >> m >> x;
  c.resize(n);
  d.resize(n);
  a.resize(n);
  for (int i = 0; i < n; ++i)
    a[i].resize(m);
  for (int i = 0; i < n; ++i) {
    cin >> c[i];
    for (int j = 0; j < m; ++j)
      cin >> a[i][j];
  }
  cout << search(0) << 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++)
#define PI 3.1415926535897932384626433832795028
#define INF (1 << 29)
#define LINF (1LL << 60)
using namespace std;
using INT = long long;
using P = pair<int, int>;

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<vector<int>> c;
  c.resize(n);
  vector<int> ar(m, 0);
  vector<int> cost(n);
  rep(i, n) {
    cin >> cost[i];
    rep(j, m) {
      int a;
      cin >> a;
      c[i].emplace_back(a);
    }
  }
  int mini = INF;
  rep(i, 1 << n) {
    int cos = 0;
    rep(j, n) {
      if (i >> j & 1) {
        rep(k, m) { ar[k] += c[j][k]; }
        cos += cost[j];
      }
    }
    rep(j, m) {
      if (ar[j] < x) {
        cos += INF;
        break;
      }
    }
    mini = min(mini, cos);
    ar = vector<int>(m);
  }
  if (mini == INF)
    cout << -1 << endl;
  else
    cout << mini << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define PI 3.1415926535897932384626433832795028
#define INF (1 << 29)
#define LINF (1LL << 60)
using namespace std;
using INT = long long;
using P = pair<int, int>;

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<vector<int>> c;
  c.resize(n);
  vector<int> ar(m, 0);
  vector<int> cost(n);
  rep(i, n) {
    cin >> cost[i];
    rep(j, m) {
      int a;
      cin >> a;
      c[i].emplace_back(a);
    }
  }
  int mini = INF;
  rep(i, 1 << n) {
    int cos = 0;
    rep(j, n) {
      if (i >> j & 1) {
        rep(k, n) { ar[k] += c[j][k]; }
        cos += cost[j];
      }
    }
    rep(j, m) {
      if (ar[j] < x) {
        cos += INF;
        break;
      }
    }
    mini = min(mini, cos);
    ar = vector<int>(m);
  }
  if (mini == INF)
    cout << -1 << endl;
  else
    cout << mini << endl;
  return 0;
}
Problem p02683 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstring>
#include <iostream>

using namespace std;

struct node {
  int c;     // 书的价格
  int a[15]; // 这本书能够提升Ta的第j个算法多少等级
} book[15];  // 储存每本书的信息
int b[15];   // 统计这一个子集能够提升第j个算法的总等级

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  for (int i = 0; i < n; i++) {
    cin >> book[i].c;
    for (int j = 0; j < m; j++)
      cin >> book[i].a[j];
  }
  int ans = 2e9;
  for (int i = 0; i < (1 << n); i++) {
    memset(b, 0, sizeof b);
    int sum = 0; // 统计每一个子集所有书的总价格
    for (int j = 0; j < n; j++)
      if (i >> j & 1) {
        sum += book[j].c;
        for (int k = 0; k < m; k++)
          b[k] += book[j].a[k];
      }
    bool flag = 1; // 判断是否m个算法都大于等于x，1为是，0为否
    for (int j = 0; j < m; j++)
      if (b[j] < x)
        flag = 0;
    if (flag)
      ans = min(ans, sum); // 每次选出更小的价格
  }
  if (ans == 2e9)
    cout << "-1";
  else
    cout << ans;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <stdio.h>
#define debug                                                                  \\
  freopen("in.txt", "r", stdin);                                               \\
  freopen("out.txt", "w", stdout)
using namespace std;
const int MAXN = 20;
typedef long long ll;
int a[MAXN][MAXN], vis[MAXN], ans[MAXN], mon[MAXN];
int n, m, x, sum = 0, price = 1e9, res;
void dfs(int pos) {
  int flag = 0;
  for (int i = 1; i <= m; i++) {
    if (ans[i] < x) {
      flag = 1;
      break;
    }
  }
  if (!flag) {
    price = min(sum, price);
    return;
  }
  if (pos == n + 1) {
    res = 1;
    return;
  }
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      vis[i] = 1;
      for (int j = 1; j <= m; j++)
        ans[j] += a[i][j];
      sum += mon[i];
      dfs(pos + 1);
      vis[i] = 0;
      sum -= mon[i];
      for (int j = 1; j <= m; j++)
        ans[j] -= a[i][j];
    }
  }
}
int main() {
  cin >> n >> m >> x;
  for (int i = 1; i <= n; i++) {
    cin >> mon[i];
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
    }
  }
  dfs(1);
  if (res)
    cout << -1 << '\\n';
  else
    cout << price << '\\n';
  return 0;
}
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;

int N, M, X, n;
ll cost, mi;
int B[20], ans[20]; // B是每个算法的总理解度
bool flag;

struct node {
  int A[20], C; // A是书能给的理解度 ，C是书的钱
} nod[20];

void dfs(int u, int last) {
  if (u == n) {
    cost = 0;
    memset(B, 0, sizeof(B));
    for (int i = 0; i < u; i++) {
      for (int j = 0; j < M; j++) {
        B[j] += nod[ans[i]].A[j];
      }
      cost += nod[ans[i]].C;
    }
    flag = true;
    // printf("cost=%d",cost) ;
    for (int i = 0; i < M; i++) {
      if (B[i] < X) {
        flag = false;
        break;
      }
    }
    if (flag) {
      mi = min(cost, mi);
    }
    return;
  }
  for (int i = 1; i <= N; i++) {
    if (i > last) {
      last = i;
      ans[u] = i;
      dfs(u + 1, last);
    }
  }
}

int main() {
  scanf("%d%d%d", &N, &M, &X);
  for (int i = 1; i <= N; i++) {
    scanf("%d", &nod[i].C);
    for (int j = 0; j < M; j++) {
      scanf("%d", &nod[i].A[j]);
    }
  }
  mi = 1e10;
  for (n = 1; n <= N; n++) {
    dfs(0, 0);
  }
  if (mi == 1e10) {
    printf("-1");
  } else {
    printf("%lld", mi);
  }
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

struct node {
  int c;
  int a[15];
} book[15];

int main() {
  freopen("input.txt", "r", stdin);

  int n, m, x;
  cin >> n >> m >> x;
  for (int i = 0; i < n; i++) {
    cin >> book[i].c;
    for (int j = 0; j < m; j++)
      cin >> book[i].a[j];
  }
  //	for(int i=0;i<n;i++)
  //	{
  //		cout<<book[i].c<<" ";
  //		for(int j=0;j<m;j++) cout<<book[i].a[j];
  //		puts("");
  //	}
  int ans = -1;
  for (int i = 0; i < (1 << n); i++) {
    int sum = 0;
    int b[m + 5]; // 随机值啊
    memset(b, 0, sizeof b);
    for (int j = 0; j < n; j++)
      if ((i >> j) & 1) {
        sum += book[j].c;
        for (int k = 0; k < m; k++)
          b[k] += book[j].a[k];
      }
    bool flag = 1;
    for (int j = 0; j < m; j++)
      if (b[j] < x)
        flag = 0;
    if (flag) {
      if (ans == -1)
        ans = sum;
      else
        ans = min(ans, sum);
    }
  }
  cout << ans << endl;

  return 0;
}

// 每行第一个数前不输出
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

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

const int INF = 1001001001;

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

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, x;
  cin >> n >> m >> x;
  int a[15][15];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m + 1; i++) {
      cin >> a[i][j];
    }
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m + 1; i++) {
      cout << a[i][j];
    }
    cout << endl;
  }
  return 0;
}
Problem p02683 (C++) — buggy submission, verdict: Time Limit Exceeded

// author: Harsh :)
// Iterating over each of the 2^n subsets with bitmasking
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define F first
#define S second
const ll mod = 1e9 + 7;
const ll INF = 922337203685477;
#define pb push_back
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define fastio                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);
#define maxN 100007
using namespace std;
int main() {
  fastio;
  ll n = 0, m = 0, x = 0;
  cin >> n >> m >> x;
  ll cost[n] = {0}, ar[n][m] = {0};
  for (ll i = 0; i < n; ++i) {
    cin >> cost[i];
    for (ll j = 0; j < m; ++j)
      cin >> ar[i][j];
  }
  ll best = INT_MAX;
  for (ll mask = 0; mask < (1ll << n); ++mask) {
    ll curr_sum = 0;
    ll understanding[m] = {0};
    for (ll i = 0; i < n; ++i) {
      if (mask & (1ll << i)) {
        curr_sum += cost[i];
        for (ll j = 0; j < m; ++j)
          understanding[j] += ar[i][j];
      }
    }
    bool possible = true;
    for (ll i = 0; i < m; ++i) {
      if (understanding[i] < x) {
        possible = false;
        break;
      }
    }
    if (possible)
      best = min(best, curr_sum);
  }
  if (best != INT_MAX)
    cout << best;
  else
    cout << "-1";
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
#define F first
#define S second
const ll mod = 1e9 + 7;
const ll INF = 922337203685477;
#define pb push_back
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define fastio                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);
using namespace std;
ll c[15] = {0}, a[15][15] = {0}, val[15] = {0}, ans = INT_MAX, n, m, k;
void fun(ll x, ll y) {
  bool f = true;
  for (ll i = 0; i < m; ++i) {
    if (val[i] < k) {
      f = false;
      break;
    }
  }
  if (f)
    ans = min(ans, x);
  for (ll i = y; i < n; ++i) {
    for (ll j = 0; j < m; ++j) {
      val[j] += a[i][j];
    }
    fun(x + c[i], y + 1);
    for (ll j = 0; j < m; ++j) {
      val[j] -= a[i][j];
    }
  }
}
int main() {
  fastio;
  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];
    }
  }
  fun(0, 0);
  if (ans == INT_MAX)
    ans = -1;
  cout << ans;
  return 0;
}
Problem p02683 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <climits>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long int;

int main() {
  ll N, M, X;
  cin >> N >> M >> X;

  vector<vector<ll>> book(N, vector<ll>(M));
  vector<ll> money(N);

  for (ll i = 0; i < N; i++) {
    cin >> money[i];

    for (ll j = 0; j < M; j++) {
      cin >> book[i][j];
    }
  }

  ll ans = INT_MAX;

  for (ll i = 0; i < (1 << N); i++) {
    vector<ll> rikai(M, 0);
    ll cur = 0;

    for (ll j = 0; j < N; j++) {
      if (bitset<64>(i)[j] == 0) {
        continue;
      }

      cur += money[j];

      for (ll k = 0; k < M; k++) {
        rikai[k] += book[j][k];
      }
    }
    bool ok = true;
    for (ll j = 0; j < M; j++) {
      if (rikai[j] < X) {
        ok = false;
      }
    }

    if (ok) {
      ans = min(ans, cur);
    }
  }

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

Error: TLE

Fixed submission:

#include <algorithm>
#include <climits>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long int;

int main() {
  ll N, M, X;
  cin >> N >> M >> X;

  vector<vector<ll>> book(N, vector<ll>(M));
  vector<ll> money(N);

  for (ll i = 0; i < N; i++) {
    cin >> money[i];

    for (ll j = 0; j < M; j++) {
      cin >> book[i][j];
    }
  }

  vector<ll> perm(N);
  for (ll i = 0; i < N; i++) {
    perm[i] = i;
  }

  ll ans = INT_MAX;

  do {
    vector<ll> rikai(M, 0);
    ll cur = 0;

    for (ll i = 0; i < N; i++) {
      ll buy = perm[i];
      cur += money[buy];

      for (ll j = 0; j < M; j++) {
        rikai[j] += book[buy][j];
      }

      bool ok = true;
      for (ll j = 0; j < M; j++) {
        if (rikai[j] < X) {
          ok = false;
        }
      }

      if (!ok) {
        continue;
      }

      ans = min(ans, cur);
      break;
    }
  } while (next_permutation(perm.begin(), perm.end()));

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

#include <bits/stdc++.h>
using namespace std;
void func(int nn);
int n, m, x;
int kin[12], rk[12][12];
int sum, box[12], MIN;
int main(void) {
  int i, j;
  cin >> n >> m >> x;
  for (i = 0; i < n; i++) {
    cin >> kin[i];
    for (j = 0; j < m; j++) {
      cin >> rk[i][j];
    }
  }
  // for(i=0;i<n;i++){
  // cout<<kin[i];
  // for(j=0;j<m;j++){
  // cout<<" "<<rk[i][j];
  // }
  // cout<<endl;
  // }
  sum = 0;
  for (i = 0; i < n; i++)
    box[i] = 0;
  MIN = INT_MAX;
  func(0);
  if (MIN == INT_MAX)
    cout << -1 << endl;
  else
    cout << MIN << endl;
  return 0;
}
void func(int nn) {
  int i, flg;
  // cout<<"nn="<<nn<<endl;
  // for(i=0;i<n;i++)	cout<<box[i]<<" ";
  // cout<<endl;
  if (nn == 12) {
    flg = 1;
    for (i = 0; i < m; i++) {
      if (x > box[i])
        flg = 0;
    }
    if (flg == 1)
      MIN = min(MIN, sum);
  } else {
    func(nn + 1);
    sum += kin[nn];
    for (i = 0; i < m; i++)
      box[i] += rk[nn][i];
    func(nn + 1);
    sum -= kin[nn];
    for (i = 0; i < m; i++)
      box[i] -= rk[nn][i];
  }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int func(int nn);
int n, m, x;
int kin[12], rk[12][12];
int sum, box[12], MIN;
int main(void) {
  int i, j;
  cin >> n >> m >> x;
  for (i = 0; i < n; i++) {
    cin >> kin[i];
    for (j = 0; j < m; j++) {
      cin >> rk[i][j];
    }
  }
  // for(i=0;i<n;i++){
  // cout<<kin[i];
  // for(j=0;j<m;j++){
  // cout<<" "<<rk[i][j];
  // }
  // cout<<endl;
  // }
  sum = 0;
  for (i = 0; i < n; i++)
    box[i] = 0;
  MIN = INT_MAX;
  func(0);
  if (MIN == INT_MAX)
    cout << -1 << endl;
  else
    cout << MIN << endl;
}
int func(int nn) {
  int i, flg;
  // cout<<"nn="<<nn<<endl;
  // for(i=0;i<n;i++)	cout<<box[i]<<" ";
  // cout<<endl;
  if (nn == 12) {
    flg = 1;
    for (i = 0; i < m; i++) {
      if (x > box[i])
        flg = 0;
    }
    if (flg == 1)
      MIN = min(MIN, sum);
  } else {
    func(nn + 1);
    sum += kin[nn];
    for (i = 0; i < m; i++)
      box[i] += rk[nn][i];
    func(nn + 1);
    sum -= kin[nn];
    for (i = 0; i < m; i++)
      box[i] -= rk[nn][i];
  }
}