alexjercan/bugnet huggingface dataset:
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<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];
    }
  }

  bool can1 = false;
  int min = 0;
  for (int tmp = 0; tmp < (1 << n); ++tmp) {
    bitset<12> s(tmp);
    bool can2 = true;
    for (int i = 0; i < m; ++i) {
      int und = 0;
      for (int j = 0; j < n; ++j) {
        if (s.test(j)) {
          und += a[j][i];
        }
      }
      if (und < x) {
        can2 = false;
        break;
      }
    }
    if (can2) {
      can1 = true;
      int cost = 0;
      for (int i = 0; i < n; ++i) {
        if (s.test(i)) {
          cost += c[i];
        }
      }
      if (min > cost || min == 0) {
        min = cost;
      }
    }
  }

  if (can1) {
    cout << min << endl;
  } else {
    cout << "-1" << endl;
  }
}


Error: -11

Fixed submission:

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

int binary(int bina) {
  int ans = 0;
  for (int i = 0; bina > 0; i++) {
    ans = ans + (bina % 2) * pow(10, i);
    bina = bina / 2;
  }
  return ans;
}

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

  int num;
  string numStr;
  bool can = true;
  int minyen = 0;
  for (int i = 0; i < (int)pow(2, N); i++) {
    num = binary(i);
    ostringstream tmp;
    tmp << setfill('0') << setw(N) << num;
    numStr = tmp.str();
    for (int j = 0; j < M; j++) {
      int r = 0;
      for (int l = 0; l < N; l++) {
        r += rikai[N][j] * (numStr[l] - '0');
      }
      if (r < 10) {
        can = false;
        break;
      } else {
        can = true;
      }
    }
    if (!can) {
      continue;
    }
    int yen = 0;
    for (int l = 0; l < N; l++) {
      yen += cost[l] * (numStr[l] - '0');
    }
    if (yen < minyen || minyen == 0) {
      minyen = yen;
    }
  }

  if (minyen > 0) {
    cout << minyen << endl;
  } else {
    cout << "-1" << endl;
  }
  return 0;
}
Problem p02683 (C++) — buggy submission, verdict: Time Limit Exceeded

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

typedef long long int ll;
ll powk(ll a, ll n = 2) {
  ll r = 1;
  for (ll i = 0; i < n; i++) {
    r *= a;
  }

  return r;
}

int main() {
  ll n, m, x;
  cin >> n >> m >> x;
  vector<pair<ll, vector<ll>>> ca(n);
  for (ll i = 0; i < n; i++) {
    cin >> ca[i].first;
    ca[i].second = vector<ll>(m);
    for (ll j = 0; j < m; j++) {
      cin >> ca[i].second[j];
    }
  }

  ll ans = 1e9;
  for (ll i = 0; i < (1 << n); i++) {
    vector<ll> s;
    for (ll j = 0; j < n; j++) {
      if (i & (1 << j)) {
        s.push_back(j);
      }
    }

    ll tans = 0;
    vector<ll> r(m);
    for (ll j = 0; j < s.size(); j++) {
      for (ll k = 0; k < m; k++) {
        r[k] += ca[s[j]].second[k];
      }
      tans += ca[s[j]].first;
    }

    bool f = true;
    for (ll j = 0; j < m; j++) {
      if (r[j] < x) {
        f = false;
      }
    }
    if (f) {
      ans = min(tans, ans);
    }
  }

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

  return 0;
}

Error: TLE

Fixed submission:

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

typedef long long int ll;
ll powk(ll a, ll n = 2) {
  ll r = 1;
  for (ll i = 0; i < n; i++) {
    r *= a;
  }

  return r;
}

ll lans = 1e9;

void dfs(vector<ll> r, ll d, vector<pair<ll, vector<ll>>> ca, vector<bool> f,
         ll ans, ll now, ll m, ll x) {
  bool tf = true;

  for (ll i = 0; i < m; i++) {
    r[i] += ca[now].second[i];
    if (r[i] < x) {
      tf = false;
    }
  }
  ans += ca[now].first;

  if (tf) {

    lans = min(lans, ans);

    return;
  }

  for (ll i = 0; i < ca.size(); i++) {
    if (f[i]) {
      f[i] = false;
      dfs(r, d + 1, ca, f, ans, i, m, x);
      f[i] = true;
    }
  }
}

int main() {
  ll n, m, x;
  cin >> n >> m >> x;
  vector<pair<ll, vector<ll>>> ca(n);
  for (ll i = 0; i < n; i++) {
    cin >> ca[i].first;
    ca[i].second = vector<ll>(m);
    for (ll j = 0; j < m; j++) {
      cin >> ca[i].second[j];
    }
  }

  vector<ll> r(m);
  vector<bool> f(n, true);
  for (ll i = 0; i < ca.size(); i++) {
    if (f[i]) {
      f[i] = false;
      dfs(r, 0, ca, f, 0, i, m, x);
    }
    f[i] = true;
  }

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

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

#include <bits/stdc++.h>
using namespace std;
#define stop exit(0)
int main() {
  vector<long long> v;
  long long a, b, c = 0, d = 0, e = 0, f = 0, g = 0, i, j, k = 1, l = 0, r = 1,
                  n, m[4097], z[4097][13], h[13][13], p[13];
  string s, t, x, y;
  double q, u, w;
  cin >> a >> b >> c;
  for (i = 1; i <= a; i++) {
    cin >> p[i];
    for (j = 1; j <= b; j++) {
      cin >> h[i][j];
    }
  }
  d = a;
  while (d--) {
    k *= 2;
  }
  for (i = 1; i < k; i++) {
    for (j = 1; j <= b; j++) {
      z[i][j] = 0;
    }
    d = i;
    e = a;
    r = 0;
    m[i] = 0;
    while (d > 0) {
      if (d % 2 == 1) {
        for (j = 1; j <= b; j++) {
          z[i][j] += h[e][j];
        }
        m[i] += p[e];
      }
      e--;
      d /= 2;
    }
    for (j = 1; j <= b; j++) {
      if (z[i][j] < c) {
        r = 1;
        break;
      }
    }
    if (r == 0) {
      v.push_back(m[i]);
      l = 1;
    }
  }
  sort(v.begin(), v.end());
  if (l == 1) {
    cout << v[0];
  } else {
    cout << -1;
  }
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define stop exit(0)
int main() {
  vector<long long> v;
  long long a, b, c = 0, d = 0, e = 0, f = 0, g = 0, i, j, k = 1, l = 0, r = 1,
                  n, m[1025], z[1025][13], h[13][13], p[13];
  string s, t, x, y;
  double q, u, w;
  cin >> a >> b >> c;
  for (i = 1; i <= a; i++) {
    cin >> p[i];
    for (j = 1; j <= b; j++) {
      cin >> h[i][j];
    }
  }
  d = a;
  e = a;
  while (d--) {
    k *= 2;
  }
  for (i = 1; i < k; i++) {
    d = i;
    e = a;
    m[i] = 0;
    while (d > 0) {
      if (d % 2 == 1) {
        for (j = 1; j <= b; j++) {
          z[i][j] += h[e][j];
        }
        m[i] += p[e];
      }
      e--;
      d /= 2;
    }
    for (j = 1; j <= b; j++) {
      if (z[i][j] < c) {
        break;
      }
    }
    if (j < b - 1) {
      continue;
    }
    v.push_back(m[i]);
  }
  sort(v.begin(), v.end());
  if (v.size() > 0) {
    cout << v[0];
  } else {
    cout << -1;
  }
}
Problem p02683 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define INF INT_MAX
#define ll long long
#define ull unsigned long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define FOR(i, s, e) for (ll i = s; i < e; ++i)
#define MOD 1000000007
using namespace std;
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() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  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]; }
  }

  vector<int> V(N);
  rep(i, N) V[i] = i;

  int ans = -1;

  for (int bit = 0; bit < (1 << N); ++bit) {
    vector<int> S;
    for (int i = 0; i < N; ++i) {
      if (bit & (1 << i)) {
        S.push_back(i);
      }
    }
    vector<int> tmp(M, 0);
    int c_tmp = 0;
    for (int i : S) {
      c_tmp += C[i];
      rep(m, M) { tmp[m] += A[i][m]; }
    }
    bool b = true;
    for (auto t : tmp) {
      if (t < X)
        b = false;
    }
    if (b) {
      if (ans == -1)
        ans = c_tmp;
      else
        ans = min(c_tmp, ans);
    }
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define INF INT_MAX
#define ll long long
#define ull unsigned long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define FOR(i, s, e) for (ll i = s; i < e; ++i)
#define MOD 1000000007
using namespace std;
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() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  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]; }
  }

  vector<int> V(N);
  rep(i, N) V[i] = i;

  int ans = -1;
  do {
    int c_tmp = 0;
    vector<int> tmp(M, 0);
    for (auto v : V) {
      c_tmp += C[v];
      rep(m, M) { tmp[m] += A[v][m]; }
      bool b = true;
      rep(m, M) {
        if (tmp[m] < X) {
          b = false;
          break;
        }
      }
      if (b) {
        if (ans == -1)
          ans = c_tmp;
        else
          ans = min(c_tmp, ans);
        break;
      }
    }
  } while (next_permutation(V.begin(), V.end()));
  cout << ans << endl;
}
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  ll N, M, X, count = 0, answer = 0;
  cin >> N >> M >> X;
  vector<vector<ll>> vec(N, vector<ll>(M + 1));
  for (ll i = 0; i < N; i++) {
    for (ll j = 0; j <= M; j++) {
      cin >> vec.at(i).at(j);
    }
    answer += vec.at(i).at(0);
  }
  for (ll bit = 0; bit < (1 << N); bit++) {
    ll price = 0;
    vector<ll> ans(M);
    for (ll i = 0; i < N; ++i) {
      if (bit & (1 << i)) {
        for (ll j = 0; j < M; j++) {
          ans.at(j) += vec.at(i).at(j + 1);
        }
        price += vec.at(i).at(0);
      }
    }
    for (ll i = 0; i < M; i++) {
      if (ans.at(i) < X) {
        count++;
        break;
      }
      if (i == M - 1) {
        if (answer > price) {
          answer = price;
        }
      }
      ans.at(i) = 0;
    }
  }
  if (count == 1 << N) {
    cout << -1 << endl;
    return 0;
  }
  cout << answer << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  ll N, M, X, count = 0, answer = 0;
  cin >> N >> M >> X;
  vector<vector<ll>> vec(N, vector<ll>(M + 1));
  for (ll i = 0; i < N; i++) {
    for (ll j = 0; j <= M; j++) {
      cin >> vec.at(i).at(j);
      answer += vec.at(i).at(0);
    }
  }
  for (ll bit = 0; bit < (1 << N); bit++) {
    ll price = 0;
    vector<ll> ans(N);
    for (ll i = 0; i < N; ++i) {
      if (bit & (1 << i)) {
        for (ll j = 0; j < M; j++) {
          ans.at(j) += vec.at(i).at(j + 1);
        }
        price += vec.at(i).at(0);
      }
    }
    for (ll i = 0; i < M; i++) {
      if (ans.at(i) < X) {
        count++;
        break;
      }
      if (i == M - 1) {
        if (answer > price) {
          answer = price;
        }
      }
      ans.at(i) = 0;
    }
  }
  if (count == 1 << N) {
    cout << -1 << endl;
    return 0;
  }
  cout << answer << endl;
}
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int optimal = INT_MAX;
void call(vector<vector<int>> &v, int n, int m, int temp, int k, vector<int> tt,
          int var, int cost[]) {
  if (n == temp) {
    int flag = 1;
    for (int i = 0; i < m; i++) {
      if (tt[i] < k) {
        flag = 0;
        break;
      }
    }

    if (flag) {
      optimal = min(optimal, var);
    }
    return;
  }

  call(v, n, m, temp + 1, k, tt, var, cost);
  for (int i = 0; i < m; i++) {
    tt[i] += v[temp][i];
  }
  call(v, n, m, temp + 1, k, tt, var + cost[temp], cost);
}
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
#endif
  int n, m, k;
  cin >> n >> m >> k;
  vector<vector<int>> v(n, vector<int>(m));
  int cost[n];
  for (int i = 0; i < n; i++) {
    cin >> cost[i];
    for (int j = 0; j < m; j++) {
      cin >> v[i][j];
    }
  }
  vector<int> tt(m, 0);
  int var = 0;
  int temp = 0;
  call(v, n, m, temp, k, tt, var, cost);
  if (optimal == INT_MAX) {
    cout << -1 << endl;
  } else {
    cout << optimal << 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;
#define ll long long
int optimal = INT_MAX;
void call(vector<vector<int>> &v, int n, int m, int temp, int k, vector<int> tt,
          int var, int cost[]) {
  if (n == temp) {
    int flag = 1;
    for (int i = 0; i < m; i++) {
      if (tt[i] < k) {
        flag = 0;
        break;
      }
    }

    if (flag) {
      optimal = min(optimal, var);
    }
    return;
  }

  call(v, n, m, temp + 1, k, tt, var, cost);
  for (int i = 0; i < m; i++) {
    tt[i] += v[temp][i];
  }
  call(v, n, m, temp + 1, k, tt, var + cost[temp], cost);
}
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
#endif
  int n, m, k;
  cin >> n >> m >> k;
  vector<vector<int>> v(n, vector<int>(m));
  int cost[m];
  for (int i = 0; i < n; i++) {
    cin >> cost[i];
    for (int j = 0; j < m; j++) {
      cin >> v[i][j];
    }
  }
  vector<int> tt(m, 0);
  int var = 0;
  int temp = 0;
  call(v, n, m, temp, k, tt, var, cost);
  if (optimal == INT_MAX) {
    cout << -1 << endl;
  } else {
    cout << optimal << endl;
  }
  return 0;
}
Problem p02683 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, x, i, j, k, ans;
  cin >> n >> m >> x;
  vector<int> c(n), e(m);
  vector<vector<int>> a(n, vector<int>(m));
  for (i = 0; i < n; i++) {
    cin >> c.at(i);
    for (j = 0; j < m; j++) {
      cin >> a.at(i).at(j);
      e.at(j) += a.at(i).at(j);
    }
  }
  for (j = 0; j < m; j++)
    if (e.at(j) < x)
      break;
  if (j < m)
    cout << -1 << endl;
  else {
    ans = 10000000;
    for (k = 0; k < (1 << n); k++) {
      bitset<12> b(k);
      int an = 0;
      vector<int> d(m);
      for (i = 0; i < n; i++) {
        if (b.test(i)) {
          an += c.at(i);
          for (j = 0; j < m; j++)
            d.at(j) += a.at(i).at(j);
        }
      }
      for (j = 0; j < m; j++)
        if (d.at(j) < x)
          break;
      if (j == m)
        ans = min(ans, an);
    }
    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
void f(set<int64_t> &s, vector<int64_t> &d, vector<int64_t> &c,
       vector<vector<int64_t>> &a, int64_t &x, int64_t &answer, int64_t &n,
       int64_t &m) {
  int64_t i, j;
  if (s.size() == 0) {
    int64_t ans = 0;
    vector<int64_t> e(m);
    for (i = 0; i < n; i++) {
      ans += c.at(d.at(i));
      for (j = 0; j < m; j++)
        e.at(j) += a.at(d.at(i)).at(j);
      for (j = 0; j < m; j++)
        if (e.at(j) < x)
          break;
      if (j == m)
        break;
    }
    answer = min(answer, ans);
  } else {
    set<int64_t> t = s;
    for (auto k : t) {
      d.push_back(k);
      s.erase(k);
      f(s, d, c, a, x, answer, n, m);
      d.pop_back();
      s.insert(k);
    }
  }
}
int main() {
  int64_t n, m, x, i, j, answer;
  cin >> n >> m >> x;
  vector<int64_t> c(n), b(m), d;
  vector<vector<int64_t>> a(n, vector<int64_t>(m));
  set<int64_t> s;
  for (i = 0; i < n; i++) {
    cin >> c.at(i);
    for (j = 0; j < m; j++) {
      cin >> a.at(i).at(j);
      b.at(j) += a.at(i).at(j);
    }
    s.insert(i);
  }
  for (j = 0; j < m; j++)
    if (b.at(j) < x)
      break;
  if (j < m)
    cout << -1 << endl;
  else {
    answer = 10000000;
    f(s, d, c, a, x, answer, n, m);
    cout << answer << endl;
  }
}
Problem p02683 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

long long n, m, x, a[13][13], cost2[13], current[13];
bool visited[13];

long long solve(long long cost, int idx) {
  bool ok = true;
  for (int i = 1; i <= m; ++i) {
    current[i] += a[idx][i];
    if (current[i] < x)
      ok = false;
  }
  if (ok)
    return cost;
  long long answer = 2e18;
  for (int i = idx + 1; i <= n; ++i) {
    if (visited[i])
      continue;
    if (!visited[i]) {
      visited[i] = true;
      answer = min(answer, solve(cost + cost2[i], i));
    }
    visited[i] = false;
    for (int j = 1; j <= m; ++j)
      current[j] -= a[i][j];
  }
  return answer;
}

int main() {
  cin >> n >> m >> x;
  for (int i = 1; i <= n; ++i) {
    cin >> cost2[i];
    for (int j = 1; j <= m; ++j)
      cin >> a[i][j];
  }
  long long answer = solve(0, 0);
  cout << (answer == 2e18 ? -1 : answer);
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

long long n, m, x, a[13][13], cost2[13], current[13];
bool visited[13];

long long solve(int cost, int idx) {
  bool ok = true;
  for (int i = 1; i <= m; ++i) {
    current[i] += a[idx][i];
    if (current[i] < x)
      ok = false;
  }
  if (ok)
    return cost;
  long long answer = 2e18;
  for (int i = 1; i <= n; ++i) {
    if (visited[i])
      continue;
    if (!visited[i]) {
      visited[i] = true;
      answer = min(answer, solve(cost + cost2[i], i));
    }
    visited[i] = false;
    for (int j = 1; j <= m; ++j)
      current[j] -= a[i][j];
  }
  return answer;
}

int main() {
  cin >> n >> m >> x;
  for (int i = 1; i <= n; ++i) {
    cin >> cost2[i];
    for (int j = 1; j <= m; ++j)
      cin >> a[i][j];
  }
  long long answer = solve(0, 0);
  cout << (answer == 2e18 ? -1 : answer);
}
Problem p02683 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int sum[20], a[20][20], n, m, k, c[20];
int mini;
void check(int t) {
  for (int i = 0; i < m; i++) {
    if (sum[i] < k)
      return;
  }
  if (t < mini)
    mini = t;
}
void work(int dep, int t) {
  if (t > mini)
    return;
  if (dep >= n) {
    check(t);
    return;
  }
  for (int i = 0; i < m; i++)
    sum[i] += a[dep][i];
  work(dep + 1, t + c[dep]);
  for (int i = 0; i < m; i++)
    sum[i] -= a[dep][i];
  work(dep + 1, t);
}
int main() {
  mini = 2147483647;
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++) {
    cin >> c[i];
    for (int j = 0; j < m; j++)
      cin >> a[i][j];
  }

  work(0, 0);
  if (mini == 2147483647)
    cout << -1 << endl;
  else
    cout << mini << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
long a[100][100];
long long c[100];
long long sum[100];
int n, m;
long long x;
long long Min = 1234567891;
int used[100];

int check() {
  int i;
  for (i = 1; i <= m; i++)
    if (sum[i] < x)
      return 0;
  return 1;
}
void work(long long);

int main() {
  int flag;
  long long s = 0;
  cin >> n >> m >> x;
  memset(sum, sizeof(sum), 0);
  for (int i = 1; i <= n; i++) {
    cin >> c[i];
    s += c[i];
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
      sum[j] += a[i][j];
    }
  }
  flag = 1;
  for (int i = 1; i <= m; i++) {
    if (sum[i] < x) {
      flag = 0;
      break;
    }
  }
  if (flag == 0) {
    cout << "-1" << endl;
  } else {
    for (int i = 1; i <= n; i++)
      used[i] = 0;
    work(s);
    cout << Min << endl;
  }
  return 0;
}

void work(long long s) {
  int i, j;
  if (s < Min)
    Min = s;
  for (i = 1; i <= n; i++) {
    if (not used[i]) {
      for (j = 1; j <= m; j++) {
        sum[j] -= a[i][j];
      }
      if (check()) {
        used[i] = 1;
        work(s - c[i]);
      }
      used[i] = 0;
      for (j = 1; j <= m; j++)
        sum[j] += a[i][j];
    }
  }
}
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)
typedef long long int ll;
const int INF = 1e13 + 7;

int main() {
  ll N, M, X;
  cin >> N >> M >> X;
  vector<ll> C(N);
  vector<vector<ll>> A(N, vector<ll>(M));
  rep(i, N) {
    cin >> C.at(i);
    rep(j, M) { cin >> A.at(i).at(j); }
  }
  ll ans = INF;
  rep(mask, 1 << N) {
    ll num = 0;
    vector<ll> y(M);
    rep(i, N) {
      if (mask & (1 << i)) {
        num += C.at(i);
        rep(j, M) { y.at(j) += A.at(i).at(j); }
      }
    }
    bool b = 1;
    rep(i, M) {
      if (y.at(i) < X) {
        b = 0;
        break;
      }
    }
    if (b) {
      ans = min(ans, num);
    }
  }
  if (ans == INF) {
    cout << "-1" << endl;
  } else {
    cout << ans << endl;
  }
}


Error: 0

Fixed submission:

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

int main() {
  ll N, M, X;
  cin >> N >> M >> X;
  vector<ll> C(N);
  vector<vector<ll>> A(N, vector<ll>(M));
  rep(i, N) {
    cin >> C.at(i);
    rep(j, M) { cin >> A.at(i).at(j); }
  }
  vector<ll> B(N);
  rep(j, M) {
    ll ans = INF;
    for (int mask = 1; mask <= (1 << N); ++mask) {
      ll num = 0, y = 0;
      rep(i, N) {
        if (mask & (1 << i)) {
          num += C.at(i);
          y += A.at(i).at(j);
        }
      }
      if (y >= X) {
        ans = min(ans, num);
      }
    }
    B.at(j) = ans;
  }
  sort(B.begin(), B.end());
  if (B.at(N - 1) == INF) {
    cout << "-1" << endl;
  } else {
    cout << B.at(N - 1) << endl;
  }
}
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
const int maxn = 1e5 + 10;
int T, N, M, C, mi = 1, fi = 0;
int a[20][20];
int b[20], c[20];
// int retu(int i){

//}
int main() {
  cin >> T >> N >> M;
  for (int i = 0; i < T; i++) {
    cin >> b[i];
    mi += b[i];
    for (int j = 0; j < N; j++) {
      cin >> a[i][j];
    }
  }
  fi = mi;
  int l = pow(2, double(T));
  for (int k = 0; k < (1 << T); k++) {
    int sum = 0;
    for (int i = 0; i < 20; i++)
      c[i] = 0;
    for (int j = 0; j < T; j++) {
      if ((k >> j) & 1) {
        sum += b[j];
        for (int i = 0; i < N; i++) {
          // cout<<a[j][i]<<" ";
          c[i] += a[j][i];
        }
        // cout<<endl;
      }
    }
    int f = 1;
    for (int i = 0; i < N; i++) {
      if (c[i] < M) {
        f = 0;
        break;
        f = 0;
      }
      // cout<<c[i]<<" ";
    }
    // cout<<endl;continue;
    if (f)
      mi = min(mi, sum);
  }
  if (mi == fi)
    cout << "-1\\n";
  else
    cout << mi << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <stdio.h>
#define ios                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#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;
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) {
    cout << -1 << '\\n';
    exit(1);
  }
  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() {
  ios;
  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);
  cout << price << '\\n';
  return 0;
}