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

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
ll mod = 998244353;
ll mul(ll a, ll b) { return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b) { return ((a % mod) + (b % mod)) % mod; }
ll sub(ll a, ll b) { return ((a % mod) - (b % mod) + mod) % mod; }
ll n, m, kk;
ll a[20][20];
ll c[20];
ll out = 1e18;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m >> kk;
  vector<ll> v;
  ll arr[m];
  for (ll i = 0; i < n; i++) {

    cin >> c[i];
    for (ll j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  ll u = pow(2, n);

  for (ll i = 1; i < u; i++) {
    ll x = i;
    ll j = 0;
    vector<ll> v;
    while (x) {
      if (x % 2) {
        v.push_back(j);
      }
      x = x / 2;
      j++;
    }
    ll b[m];
    for (ll j = 0; j < m; j++) {
      b[j] = 0;
    }
    ll co = 0;
    for (ll j = 0; j < v.size(); j++) {

      co += c[v[j]];
      for (ll k = 0; k < m; k++) {
        b[k] += a[v[j]][k];
      }
    }

    ll tr = 1;
    for (ll j = 0; j < m; j++) {

      if (b[j] < kk) {
        tr = 0;
      }
    }

    if (tr == 1) {
      out = min(out, co);
    }
  }
  if (out == 1e18) {
    cout << "-1";
  } else {
    cout << out;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
ll mod = 998244353;
ll mul(ll a, ll b) { return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b) { return ((a % mod) + (b % mod)) % mod; }
ll sub(ll a, ll b) { return ((a % mod) - (b % mod) + mod) % mod; }
ll n, m, x;
ll a[20][20];
ll c[20];
ll out = 1e18;
void ch(vector<ll> v, ll arr[], ll tot) {
  ll tr = 1;
  // cout<<v.size()<<"\\n";
  for (ll i = 0; i < m; i++) {
    // cout<<arr[i]<<" ";
    if (arr[i] < x) {
      tr = 0;
    }
  }
  // cout<<"\\n";
  if (tr) {

    out = min(tot, out);
    return;
  }
  for (ll i = 0; i < v.size(); i++) {
    vector<ll> t = v;
    t.erase(t.begin() + i);
    ll b[m];
    for (ll j = 0; j < m; j++) {
      b[j] = arr[j] + a[v[i]][j];
    }
    ch(t, b, tot + c[v[i]]);
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m >> x;
  vector<ll> v;
  ll arr[m];
  for (ll i = 0; i < n; i++) {

    cin >> c[i];
    v.push_back(i);
    for (ll j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  for (ll j = 0; j < m; j++) {
    arr[j] = 0;
  }
  ch(v, arr, 0);
  if (out == 1e18) {
    cout << "-1";
    exit(0);
  }
  cout << out;
}
Problem p02683 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int a[12][12];
int main() {
  long long 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 = 100000000;
  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 == 100000000) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

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

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

  vector<vector<long long>> A(N, vector<long long>(M + 1));
  for (long long i = 0; i < N; i++) {
    for (long long j = 0; j < M + 1; j++) {
      cin >> A[i][j];
    }
  }

  long long ans = pow(10, 10);
  vector<int> v(N);
  iota(v.begin(), v.end(), 1);
  do {
    vector<long long> tmpA(M);
    long long tmpans = 0;
    for (auto x : v) {
      tmpans += A[x - 1][0];
      for (long long j = 0; j < M; j++) {
        tmpA[j] += A[x - 1][j + 1];
      }
      bool ok = true;
      for (long long j = 0; j < M; j++) {
        if (tmpA[j] < X) {
          ok = false;
        };
      }
      if (ok) {
        ans = min(ans, tmpans);
        break;
      }
    }
  } while (next_permutation(v.begin(), v.end())); // 次の順列を生成

  if (ans == pow(10, 10)) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}
Problem p02683 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int calc(int state, vector<vector<int>> &v, vector<int> &cost, int x) {
  int c = 0;
  vector<int> skill(v[0].size(), 0);
  for (int i = 0; i < v.size(); i++) {
    if (state & 1 << i) {
      for (int j = 0; j < v[i].size(); j++) {
        skill[j] += v[i][j];
      }
      c += cost[i];
    }
  }

  for (int i = 0; i < skill.size(); i++) {
    if (skill[i] < x)
      return INT_MAX;
  }

  return c;
}

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> cost(n);
  vector<vector<int>> v(n, vector<int>(m));

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

  int ans = INT_MAX;

  for (int i = 0; i < (1 << n); i++) {
    ans = min(ans, calc(i, v, cost, x));
  }

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

  return 0;
}

Error: TLE

Fixed submission:

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

int C = INT_MAX;
bool check(vector<int> &v, int x) {
  // cout<<x<<endl;
  for (int i = 0; i < v.size(); i++) {
    // cout<<v[i]<<" ";
    if (v[i] < x) {
      // cout<<"false v[]i ;"<<v[i]<<endl;
      return false;
    }
  }
  //     cout<<endl;

  //     cout<<"true"<<endl;
  return true;
}

void util(vector<vector<int>> &v, vector<bool> visited, vector<int> &cost,
          vector<int> ans, int c, int x, int i) {

  if (i == cost.size() || visited[i]) {
    return;
  }

  visited[i] = true;

  if (check(ans, x) == true) {
    // cout<<"cost: "<<c<<endl;
    C = min(c, C);
  }

  for (int k = 0; k < cost.size(); k++) {
    if (!visited[k])
      util(v, visited, cost, ans, c, x, k);
  }

  c += cost[i];
  for (int j = 0; j < v[0].size(); j++) {
    ans[j] += v[i][j];
    // cout<<ans[j]<<" ";
  }
  // cout<<endl;
  if (check(ans, x) == true) {
    // cout<<"cost: "<<c<<endl;
    C = min(c, C);
  }

  for (int k = 0; k < cost.size(); k++) {
    if (!visited[k])
      util(v, visited, cost, ans, c, x, k);
  }
}

int main() {

  int n, m, x;
  cin >> n >> m >> x;
  vector<int> cost(n);
  vector<vector<int>> v;
  vector<int> ans(m, 0);

  for (int i = 0; i < n; i++) {

    cin >> cost[i];

    vector<int> tv(m);
    for (int j = 0; j < m; j++) {
      cin >> tv[j];
    }
    v.push_back(tv);
  }

  if (x == 0) {
    cout << 0 << endl;
    return 0;
  }

  // int c = 0;
  // for(int i = 0;i<cost.size();i++)
  // {
  //     int id = cost[i].second;
  //     c+=cost[i].first;
  //     for(int j=0;j<m;j++)
  //     {
  //         ans[j]+=v[id][j];
  //     }
  //     if(check(ans,x))
  //     {
  //         cout<<c<<endl;
  //         return 0;
  //     }
  // }
  vector<bool> visited(n, false);
  util(v, visited, cost, ans, 0, x, 0);

  if (C == INT_MAX)
    cout << -1 << endl;
  else
    cout << C << endl;

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

#include <bits/stdc++.h>
#define repr(i, from, to) for (int(i) = (from); (i) < (to); (i)++)
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
// const bool debug=true;
const bool debug = false;
#define DEBUG if (debug == true)
#define all(x) begin((x)), end((x))
#define vprint(x)                                                              \\
  for (auto a : (x))                                                           \\
    cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, m, x;
  cin >> n >> m >> x;
  vector<vector<ll>> mat(n, vector<ll>(m));
  vector<ll> c(n);
  rep(i, n) {
    cin >> c[i];
    rep(j, m) { cin >> mat[i][j]; }
  }
  ll res = 1LL << 60;
  rep(i, 1 << n) {
    vector<ll> val(m, 0);
    ll money = 0;
    rep(j, n) {
      if (i >> j & 1) {
        money += c[j];
        rep(k, m) { val[k] += mat[j][k]; }
      }
    }
    // cout << i << endl;
    // rep(j,n) {
    //     cout << val[i] << " ";
    // }
    // cout << endl;
    // cout << "money " << money << endl;
    bool flg = true;
    rep(j, m) { flg &= val[j] >= x; }
    if (flg) {
      chmin(res, money);
    }
  }
  cout << ((res == (1LL << 60)) ? -1 : res) << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define repr(i, from, to) for (int(i) = (from); (i) < (to); (i)++)
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
// const bool debug=true;
const bool debug = false;
#define DEBUG if (debug == true)
#define all(x) begin((x)), end((x))
#define vprint(x)                                                              \\
  for (auto a : (x))                                                           \\
    cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, m, x;
  cin >> n >> m >> x;
  vector<vector<ll>> mat(n, vector<ll>(n));
  vector<ll> c(n);
  rep(i, n) {
    cin >> c[i];
    rep(j, m) { cin >> mat[i][j]; }
  }
  ll res = 1LL << 60;
  rep(i, 1 << n) {
    vector<ll> val(m, 0);
    ll money = 0;
    rep(j, n) {
      if (i >> j & 1) {
        money += c[j];
        rep(k, m) { val[k] += mat[j][k]; }
      }
    }
    // cout << i << endl;
    // rep(j,n) {
    //     cout << val[i] << " ";
    // }
    // cout << endl;
    // cout << "money " << money << endl;
    bool flg = true;
    rep(j, m) { flg &= val[j] >= x; }
    if (flg) {
      chmin(res, money);
    }
  }
  cout << ((res == (1LL << 60)) ? -1 : res) << endl;
  return 0;
}
Problem p02683 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
const int INF = 1 << 30;
const ll MOD = 1000000007;

int main(void) {

  int n, m, x;
  cin >> n >> m >> x;
  vi C(n);
  vector<vi> A(n, vi(m));
  rep(i, n) {
    cin >> C[i];
    rep(j, m) { cin >> A[i][j]; }
  }

  vi order(n);
  rep(i, n) order[i] = i;
  ll ans = INF;

  for (int bit = 0; bit < (1 << n); bit++) {
    vi sum(m, 0);
    ll tmp = 0;

    rep(i, n) {
      if (bit & (1 << i)) {
        rep(j, m) { sum[j] += A[i][j]; }
        tmp += C[i];
      }
    }
    bool flg = true;
    rep(j, m) {
      if (sum[j] < x)
        flg = false;
    }
    if (!flg)
      continue;
    ans = min(ans, tmp);
  }

  // do {
  //     vi sum(m, 0);
  //     ll tmp = 0;
  //     for(int i : order) {

  //         int ok = 0;

  //         rep(j, m) {
  //             sum[j] += A[i][j];
  //             if (sum[j] >= x) ok++;
  //         }

  //         tmp += C[i];

  //         if (ok == m) {
  //             ans = min(ans, tmp);
  //             break;
  //         }
  //     }
  // } while(next_permutation(order.begin(), order.end()));

  if (ans == INF)
    cout << -1 << endl;
  else
    cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
const int INF = 1 << 30;
const ll MOD = 1000000007;

int main(void) {

  int n, m, x;
  cin >> n >> m >> x;
  vi C(n);
  vector<vi> A(n, vi(m));
  rep(i, n) {
    cin >> C[i];
    rep(j, m) { cin >> A[i][j]; }
  }

  vi order(n);
  rep(i, n) order[i] = i;
  ll ans = INF;

  do {
    vi sum(m);
    ll tmp = 0;
    for (int i : order) {

      int ok = 0;

      rep(j, m) {
        sum[j] += A[i][j];
        if (sum[j] >= x)
          ok++;
      }

      tmp += C[i];

      if (ok == m) {
        ans = min(ans, tmp);
        break;
      }
    }
  } while (next_permutation(order.begin(), order.end()));

  if (ans == INF)
    cout << -1 << endl;
  else
    cout << ans << endl;

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

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

const int INF = 0x7f7f7f7f;

bool all_ok(vector<int> &v, int k) {
  for (int x : v) {
    if (x >= k)
      continue;

    return false;
  }

  return true;
}

int knapsack(vector<int> &temp, int i, int k, vector<vector<int>> &v, int m) {

  if (all_ok(temp, k))
    return 0;

  if (i == v.size())
    return INF;

  vector<int> t = temp;

  for (int it = 0; it < m; it++)
    temp[it] += v[i][it + 1];

  return min(v[i][0] + knapsack(temp, i + 1, k, v, m),
             knapsack(t, i + 1, k, v, m));
}
int main() {
#ifdef TarekHasan
  freopen("input.txt", "r", stdin);
#endif // TarekHasan

  int n, m, x;
  cin >> n >> m >> x;

  vector<vector<int>> v;

  for (int i = 0; i < n; i++) {
    vector<int> temp_i;
    for (int i = 0; i <= m; i++) {
      int temp;
      cin >> temp;
      temp_i.push_back(temp);
    }
    v.push_back(temp_i);
  }

  vector<int> temp;
  for (int i = 0; i < m; i++)
    temp.push_back(0);

  int ans = knapsack(temp, 0, x, v, m);

  ans >= INF ? cout << "-1\\n" : cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

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

const int INF = 0x7f7f7f7f;

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

  int arr[n][m + 1];

  for (int i = 0; i < n; i++)
    for (int j = 0; j <= m; j++)
      cin >> arr[i][j];

  vector<int> n_v;
  for (int i = 0; i < n; i++)
    n_v.push_back(i);

  int min_cost = INF;

  do {

    int res = 0;
    bool possible = true;

    for (int i = 1; i <= m; i++) {
      int sum = 0;
      for (int j = 0; j != n_v.size(); j++) {
        sum += arr[n_v[j]][i];
        if (sum >= x) {
          res = max(res, j);
          break;
        }
      }

      if (sum < x) {
        possible = false;
        break;
      }
    }

    if (possible) {
      int t_cost = 0;

      for (int i = 0; i <= res; i++) {
        t_cost += arr[n_v[i]][0];
      }

      min_cost = min(min_cost, t_cost);
    }

  } while (next_permutation(n_v.begin(), n_v.end()));

  min_cost == INF ? cout << "-1\\n" : cout << min_cost << endl;

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

// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template <typename T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef tuple<ll, ll, ll> tlll;
typedef tuple<int, int, int> tiii;
const ll mod = 1e9 + 7;
const ll inf = 1ll << 60;

int main() {
  ll ans = inf;
  int n, m, x;
  cin >> n >> m >> x;
  vector<ll> c(n);
  vector<vector<ll>> a(n, vector<ll>(m));
  rep(i, n) {
    cin >> c[i];
    rep(j, m) cin >> a[i][j];
  }
  rep(i, (1ll << n)) {
    vector<ll> b(n, 0);
    ll sum = 0;
    rep(j, n) {
      if (i & (1ll << j)) {
        sum += c[j];
        rep(k, m) { b[k] += a[j][k]; }
      }
    }
    bool f = 1;
    rep(k, m) {
      if (b[k] < x)
        f = 0;
    }
    if (f)
      chmin(ans, sum);
  }
  if (ans != inf)
    cout << ans << endl;
  else
    cout << -1 << endl;
}

Error: 0

Fixed submission:

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template <typename T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef tuple<ll, ll, ll> tlll;
typedef tuple<int, int, int> tiii;
const ll mod = 1e9 + 7;
const ll inf = 1ll << 60;

int main() {
  ll ans = inf;
  int n, m, x;
  cin >> n >> m >> x;
  vector<ll> c(n);
  vector<vector<ll>> a(n, vector<ll>(m));
  rep(i, n) {
    cin >> c[i];
    rep(j, m) cin >> a[i][j];
  }
  rep(i, 1ll << n) {
    vector<ll> b(n, 0);
    ll sum = 0;
    rep(j, n) {
      if (i & (1ll << j)) {
        sum += c[j];
        rep(k, m) { b[k] += a[j][k]; }
      }
    }
    bool f = 1;
    rep(k, m) {
      if (b[k] < x)
        f = 0;
    }
    if (f)
      chmin(ans, sum);
  }
  if (ans != inf)
    cout << ans << endl;
  else
    cout << -1 << endl;
}
Problem p02683 (C++) — buggy submission, verdict: Time Limit Exceeded

/*Code by Codercjh*/
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define fr(i, a, b) for (int i = (a); i <= (b); ++i)
#define rf(i, a, b) for (int i = (a); i >= (b); --i)
#define min(a, b) (a < b ? a : b)
#define max(a, b) (a > b ? a : b)
using namespace std;
typedef long long ll;
template <typename T> inline void read(T &x) {
  char c = getchar();
  T fh = 0;
  bool f = false;
  while (!isdigit(c))
    f |= (c == '-'), c = getchar();
  while (isdigit(c))
    fh = (fh << 1) + (fh << 3) + (c ^ 48), c = getchar();
  x = f ? -fh : fh;
  return;
}
int ans = 1e9, n, m, x, a[15][15], nl[15];
void dfs(int step, int sum, int mn) {
  if (sum > ans)
    return;
  if (mn >= x)
    return ans = sum, void();
  if (step > n)
    return;
  dfs(step + 1, sum, mn);
  mn = 1e9;
  fr(j, 1, m) nl[j] += a[step][j], mn = min(mn, nl[j]);
  dfs(step + 1, sum + a[step][0], mn);
  fr(j, 1, m) nl[j] -= a[step][j];
}
int main() {
  read(n), read(m), read(x);
  fr(i, 1, n) fr(j, 0, m) read(a[i][j]);
  dfs(1, 0, 0);
  cout << (ans == 1e9 ? -1 : ans);
  return 0;
}


Error: TLE

Fixed submission:

/*Code by Codercjh*/
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define fr(i, a, b) for (int i = (a); i <= (b); ++i)
#define rf(i, a, b) for (int i = (a); i >= (b); --i)
#define min(a, b) (a < b ? a : b)
#define max(a, b) (a > b ? a : b)
using namespace std;
typedef long long ll;
template <typename T> inline void read(T &x) {
  char c = getchar();
  T fh = 0;
  bool f = false;
  while (!isdigit(c))
    f |= (c == '-'), c = getchar();
  while (isdigit(c))
    fh = (fh << 1) + (fh << 3) + (c ^ 48), c = getchar();
  x = f ? -fh : fh;
  return;
}
int ans = 1e9, n, m, x, a[15][15], nl[15];
bool used[15];
void dfs(int step, int sum, int mn) {
  if (sum > ans)
    return;
  if (mn >= x)
    return ans = sum, void();
  if (step > n)
    return;
  fr(i, 1, n) {
    if (used[i])
      continue;
    used[i] = 1;
    sum += a[i][0];
    mn = 1e9;
    fr(j, 1, m) nl[j] += a[i][j], mn = min(mn, nl[j]);
    dfs(step + 1, sum, mn);
    sum -= a[i][0];
    fr(j, 1, m) nl[j] -= a[i][j];
    used[i] = 0;
  }
}
int main() {
  read(n), read(m), read(x);
  fr(i, 1, n) fr(j, 0, m) read(a[i][j]);
  dfs(1, 0, 0);
  cout << (ans == 1e9 ? -1 : ans);
  return 0;
}
Problem p02683 (C++) — buggy submission, verdict: Time Limit Exceeded

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

const int INF = 1000000007;

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> c(n);
  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];
  }
  int ans = INF;
  for (int bit = 1; bit < (1 << n); bit++) {
    vector<int> u(m, 0);
    int sum = 0;
    for (int i = 0; i < n; i++) {
      if ((bit >> i) & 1) {
        sum += c[i];
        for (int j = 0; j < m; j++)
          u[j] += a[i][j];
      }
    }
    bool f = true;
    for (int j = 0; j < m; j++) {
      if (u[j] < x)
        f = false;
    }
    if (f)
      ans = min(sum, ans);
  }
  if (ans == INF) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

const int INF = 1000000007;

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> c(n);
  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];
  }
  int ans = INF;
  for (int bit = 1; bit << (1 << n); bit++) {
    vector<int> u(m, 0);
    int sum = 0;
    for (int i = 0; i < n; i++) {
      if ((bit >> i) & 1) {
        sum += c[i];
        for (int j = 0; j < m; j++)
          u[j] += a[i][j];
      }
    }
    bool f = true;
    for (int j = 0; j < m; j++) {
      if (u[j] < x)
        f = false;
    }
    if (f)
      ans = min(sum, ans);
  }
  if (ans == INF) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>

using namespace std;

int n, m, x;
int c[15];
int res = 1e9;
int a[15][15];
vector<int> ans;

void f(int i) {
  //  cout << i << endl;
  if (i == n) {
    vector<int> A(m, 0);
    int sum = 0;
    for (int j = 0; j < ans.size(); j++) {
      sum += c[ans[j]];
      for (int k = 0; k < m; k++) {
        A[k] += a[ans[j]][k];
      }
    }

    for (int j = 0; j < m; j++) {
      if (A[j] < x) {
        return;
      }
    }

    res = min(res, sum);
    return;
  }

  ans.push_back(i);
  f(i + 1);
  ans.pop_back();
  f(i + 1);

  return;
}

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

  // cout << "Iji2" << endl;

  f(0);

  if (res == 1e9) {
    cout << -1 << endl;
  } else
    cout << res << endl;
}

Error: 0

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

int n, m, x;
int c[15];
int res = 1e9;
int a[15][15];
vector<int> ans;

void f(int i) {
  //  cout << i << endl;
  if (i == n) {
    vector<int> A(n, 0);
    int sum = 0;
    for (int j = 0; j < ans.size(); j++) {
      sum += c[ans[j]];
      for (int k = 0; k < m; k++) {
        A[k] += a[ans[j]][k];
      }
    }

    for (int j = 0; j < m; j++) {
      if (A[j] < x) {
        return;
      }
    }

    res = min(res, sum);
    return;
  }

  ans.push_back(i);
  f(i + 1);
  ans.pop_back();
  f(i + 1);

  return;
}

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

  // cout << "Iji2" << endl;

  f(0);

  if (res == 1e9) {
    cout << -1 << endl;
  } else
    cout << res << endl;
}