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

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vin = vector<int>;
using vll = vector<long long>;
using vvin = vector<vector<int>>;
using vvll = vector<vector<long long>>;
using vstr = vector<string>;
using vvstr = vector<vector<string>>;
using vch = vector<char>;
using vvch = vector<vector<char>>;
using vbo = vector<bool>;
using vvbo = vector<vector<bool>>;
using vpii = vector<pair<int, int>>;
using pqsin = priority_queue<int, vector<int>, greater<int>>;
#define mp make_pair
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define decp(n) cout << fixed << setprecision((int)n)
const int inf = 1e9 + 7;
const ll INF = 1e18;

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vin c(n);
  vvin a(n, vin(m));
  rep(i, n) {
    cin >> c[i];
    rep(j, m) cin >> a[i][j];
  }
  vin understand(m);
  int sum;
  bool can;
  int mi = inf;
  rep(i, 1 << n) {
    bitset<15> tmp(i);
    rep(i, m) understand[i] = 0;
    sum = 0;
    rep(j, n) {
      can = true;
      if (tmp[j]) {
        sum += c[j];
        rep(k, m) {
          understand[k] += a[j][k];
          if (can && understand[k] < x)
            can = false;
        }
      }
      if (can && tmp[j]) {
        mi = min(mi, sum);
        break;
      }
    }
  }
  if (mi != inf)
    cout << mi << endl;
  else
    cout << -1 << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vin = vector<int>;
using vll = vector<long long>;
using vvin = vector<vector<int>>;
using vvll = vector<vector<long long>>;
using vstr = vector<string>;
using vvstr = vector<vector<string>>;
using vch = vector<char>;
using vvch = vector<vector<char>>;
using vbo = vector<bool>;
using vvbo = vector<vector<bool>>;
using vpii = vector<pair<int, int>>;
using pqsin = priority_queue<int, vector<int>, greater<int>>;
#define mp make_pair
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define decp(n) cout << fixed << setprecision((int)n)
const int inf = 1e9 + 7;
const ll INF = 1e18;

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<pair<int, vin>> b(n);
  rep(i, n) {
    int c;
    vin a(m);
    cin >> c;
    rep(i, m) cin >> a[i];
    b[i] = mp(c, a);
  }
  sort(all(b));
  ll sum = 0;
  ll mi = INF;
  vin score(m);
  bool can;
  do {
    sum = 0;
    rep(i, m) score[i] = 0;
    rep(i, n) {
      sum += b[i].first;
      can = true;
      rep(j, m) {
        score[j] += b[i].second[j];
        if (can && score[j] < x)
          can = false;
      }
      if (can) {
        mi = min(mi, sum);
        break;
      }
    }
  } while (next_permutation(all(b)));
  if (mi != INF)
    cout << mi << endl;
  else
    cout << -1 << endl;
}
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
const int MIN_VAL = 1001001001;
int main(void) {
  int N, M, X;
  cin >> N >> M >> X;

  vector<int> C(N);
  int A[12][12];

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

  long long int ans = MIN_VAL;

  for (int b = 0; b < (1 << N); b++) {
    long long int C_cktmp = 0;
    vector<int> X_cktmp(M);
    for (int i = 0; i < N; i++) {
      if (b >> i & 1) {
        C_cktmp += C[i];
        for (int j = 0; j < M; j++) {
          X_cktmp[j] += A[i][j];
        }
      }
    }
    bool flag = true;
    for (int j = 0; j < M; j++) {
      if (X_cktmp[j] < X)
        flag = false;
    }
    if (flag)
      ans = min(ans, C_cktmp);
  }

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

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int MIN_VAL = 1001001001;
int main(void) {
  int N, M, X;
  cin >> N >> M >> X;

  vector<int> C(N);
  int A[N][N];

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

  long long int ans = MIN_VAL;

  for (int b = 0; b < (1 << N); b++) {
    long long int C_cktmp = 0;
    vector<int> X_cktmp(M);
    for (int i = 0; i < N; i++) {
      if (b >> i & 1) {
        C_cktmp += C[i];
        for (int j = 0; j < M; j++) {
          X_cktmp[j] += A[i][j];
        }
      }
    }
    bool flag = true;
    for (int j = 0; j < M; j++) {
      if (X_cktmp[j] < X)
        flag = false;
    }
    if (flag)
      ans = min(ans, C_cktmp);
  }

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

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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<ll>>;
int main() {
  ll N, K, b;
  cin >> N >> K >> b;
  vector<vector<ll>> vec(N, vector<ll>(K + 1));
  ll d = 0;
  for (ll i = 0; i < N; i++) {
    for (ll j = 0; j < K + 1; j++) {
      cin >> vec.at(i).at(j);
    }
    d += vec.at(i).at(0);
  }
  d = d + 1;
  ll re = d;
  const ll n = N;
  for (int tmp = 0; tmp < (1 << N); tmp++) {
    bitset<12> s(tmp);
    vector<ll> veco(K + 1, 0);
    // ビット列を出力
    for (ll i = 0; i < N; i++) {
      for (ll k = 0; k < K + 1; k++) {
        if (s.test(i)) {
          veco.at(k) += vec.at(i).at(k);
        }
      }
    }
    for (ll i = 1; i < K + 1; i++) {
      if (veco.at(i) < b)
        break;
      if (i == K) {
        re = min(re, veco.at(0));
      }
    }
  }
  if (re == d) {
    re = -1;
  }
  cout << re << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<ll>>;
int main() {
  ll N, K, b;
  cin >> N >> K >> b;
  vector<vector<ll>> vec(N, vector<ll>(K + 1));
  ll d = 0;
  for (ll i = 0; i < N; i++) {
    for (ll j = 0; j < K + 1; j++) {
      cin >> vec.at(i).at(j);
    }
    d += vec.at(i).at(0);
  }
  d = d + 1;
  ll re = d;
  const ll n = N;
  for (int tmp = 0; tmp < (1 << N); tmp++) {
    bitset<8> s(tmp);
    vector<ll> veco(K + 1, 0);
    // ビット列を出力
    for (ll i = 0; i < N; i++) {
      for (ll k = 0; k < K + 1; k++) {
        if (s.test(i)) {
          veco.at(k) += vec.at(i).at(k);
        }
      }
    }
    for (ll i = 1; i < K + 1; i++) {
      if (veco.at(i) < b)
        break;
      if (i == K) {
        re = min(re, veco.at(0));
      }
    }
  }
  if (re == d) {
    re = -1;
  }
  cout << re << endl;
  return 0;
}
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, x;
  cin >> n >> m >> x;
  int c[50], a[50][50], sum[50], ans[4097], cnt = 0;
  memset(ans, 0, sizeof(ans));
  for (int i = 1; i <= n; i++) {
    cin >> c[i];
    for (int j = 1; j <= m; j++)
      cin >> a[i][j];
  }
  for (int i = 0; i < (1 << n); i++) {
    memset(sum, 0, sizeof(sum));
    int cost = 0;
    for (int j = 0; j < n; j++)
      if (i & (1 << j)) {
        cost += c[j + 1];
        for (int k = 1; k <= m; k++)
          sum[k] += a[j + 1][k];
      }
    bool bad = 0;
    for (int j = 1; j <= m; j++)
      if (sum[j] < x) {
        bad = 1;
        break;
      }
    if (!bad)
      ans[++cnt] = cost;
  }
  sort(ans + 1, ans + cnt + 1);
  if (ans[1] == 0)
    cout << -1;
  else
    cout << ans[1];
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, x;
  cin >> n >> m >> x;
  int c[50], a[50][50], sum[50], ans[50] = {0}, cnt = 0;
  for (int i = 1; i <= n; i++) {
    cin >> c[i];
    for (int j = 1; j <= m; j++)
      cin >> a[i][j];
  }
  for (int i = 0; i < (1 << n); i++) {
    memset(sum, 0, sizeof(sum));
    int cost = 0;
    for (int j = 0; j < n; j++)
      if (i & (1 << j)) {
        cost += c[j + 1];
        for (int k = 1; k <= m; k++)
          sum[k] += a[j + 1][k];
      }
    bool bad = 0;
    for (int j = 1; j <= m; j++)
      if (sum[j] < x) {
        bad = 1;
        break;
      }
    if (!bad)
      ans[++cnt] = cost;
  }
  sort(ans + 1, ans + cnt + 1);
  if (ans[1] == 0)
    cout << -1;
  else
    cout << ans[1];
  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++)
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1 << 30) - 1)
#define LINF (1LL << 60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

int a[15][15];
int price[15];

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  rep(i, n) {
    int c;
    cin >> c;
    price[i] = c;
    rep(j, m) { cin >> a[i][j]; }
  }
  int ans = INF;
  for (int bit = 0; bit < (1 << n); bit++) {
    int understanding[m];
    int sum_price = 0;
    rep(i, m) understanding[i] = 0;
    rep(i, n) {
      if (bit & (1 << i)) {
        sum_price += price[i];
        rep(j, m) { understanding[j] += a[i][j]; }
      }
    }
    bool ok = true;
    rep(i, m) {
      if (understanding[i] < x) {
        ok = false;
        break;
      }
    }
    if (ok)
      ans = min(ans, sum_price);
  }
  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++)
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1 << 30) - 1)
#define LINF (1LL << 60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

int a[15][15];
int price[15];

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

#include <iostream>
#include <vector>

using namespace std;

int main(void) {
  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.at(i);
    for (int j = 0; j < M; j++) {
      cin >> A.at(i).at(j);
    }
  }

  int max = 1;

  for (int i = 0; i < N; i++) {
    max *= 2;
  }

  int minans = 1000000000;
  int crtans = 0;

  for (int i = 0; i < max; i++) {
    vector<int> binary(N, 0);
    vector<int> ability(M, 0);
    for (int j = 0; j < N; j++) {
      binary.at(j) = ((i >> j) & 1);
    }

    for (int j = 0; j < N; j++) {
      if (binary.at(j) == 1) {
        for (int k = 0; k < M; k++) {
          ability.at(k) += A.at(j).at(k);
        }
        crtans += C.at(j);
      }
    }

    bool isOk = true;

    for (int j = 0; j < M; j++) {
      if (ability.at(j) < X) {
        isOk = false;
        break;
      }
    }

    if (isOk) {
      if (minans > crtans) {
        minans = crtans;
      }
    }

    crtans = 0;
  }

  if (minans == 1000000000) {
    minans = -1;
  }

  cout << minans << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

int main(void) {
  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.at(i);
    for (int j = 0; j < M; j++) {
      cin >> A.at(i).at(j);
    }
  }

  int max = 1;

  for (int i = 0; i < N; i++) {
    max *= 2;
  }

  int minans = 1000000000;
  int crtans = 0;

  for (int i = 0; i < max; i++) {
    vector<int> binary(N, 0);
    vector<int> ability(N, 0);
    for (int j = 0; j < N; j++) {
      binary.at(j) = ((i >> j) & 1);
    }

    for (int j = 0; j < N; j++) {
      if (binary.at(j) == 1) {
        for (int k = 0; k < M; k++) {
          ability.at(k) += A.at(j).at(k);
        }
        crtans += C.at(j);
      }
    }

    bool isOk = true;

    for (int j = 0; j < M; j++) {
      if (ability.at(j) < X) {
        isOk = false;
        break;
      }
    }

    if (isOk) {
      if (minans > crtans) {
        minans = crtans;
      }
    }

    crtans = 0;
  }

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

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

int n, m, x;
vector<int> c(12);
vector<vector<int>> a(12, vector<int>(12));
vector<bool> table(14, false);

const int MX = 1001001001;

int calcPrice() {
  int price = 0;
  for (int i = 0; i < n; i++) {
    if (table[i]) {
      price += c[i];
    }
  }

  for (int i = 0; i < m; i++) {
    int syujuku = 0;
    for (int j = 0; j < n; j++) {
      if (table[j]) {
        syujuku += a[j][i];
      }
    }

    if (syujuku < x) {
      return MX;
    }
  }

  return price;
}

int culc_min(int i) {
  int ans = calcPrice();

  if (i < n) {
    table[i] = true;
    ans = min(ans, culc_min(i + 1));

    table[i] = false;
    ans = min(ans, culc_min(i + 1));
  }

  return ans;
}

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

  int ans = culc_min(0);
  if (ans == MX) {
    ans = -1;
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

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

int n, m, x;
int c[12];
vector<int> a[12];

ll culc_money(ll now, int k, vector<int> b, vector<int> ri) {
  int flag = 1;
  vector<int> b2 = b;
  vector<int> ri2 = ri;

  b2[k] = 1;
  now += c[k];
  for (int i = 0; i < m; i++) {
    ri2[i] += a[k][i];
    if (ri2[i] < x) {
      flag = 0;
    }
  }

  if (flag == 1) {
    return now;
  }

  int unpo = 1;
  ll ans = 1001001001;
  for (int i = 0; i < n; i++) {
    if (b2[i] == 0) {
      ll tmp;
      unpo = 0;
      tmp = culc_money(now, i, b2, ri2);
      if (tmp < ans) {
        ans = tmp;
      }
    }
  }

  if (unpo == 1) {
    return -1;
  } else {
    return ans;
  }
}

int main() {
  cin >> n >> m >> x;
  for (int i = 0; i < n; i++) {
    cin >> c[i];
    for (int j = 0; j < m; j++) {
      int tmp;
      cin >> tmp;
      a[i].push_back(tmp);
    }
  }

  ll ans = 1001001001;
  for (int i = 0; i < n; i++) {
    ll tmp;
    vector<int> b(12, 0);
    vector<int> ri(12, 0);
    tmp = culc_money(0, i, b, ri);
    if (tmp < ans) {
      ans = tmp;
    }
  }

  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 ll = long long;
int a[10010][10010];
int main() {
  int n, m, x;
  ll ans = 9999999999999;
  cin >> n >> m >> x;
  vector<int> c(n);
  rep(i, n) {
    cin >> c[i];
    rep(j, m) cin >> a[i][j];
  }
  rep(i, 1 << n) {
    ll cost = 0;
    vector<ll> t(m);
    rep(j, m) t[j] = 0;
    bool flag = true;
    rep(j, n) {
      if (i >> j & 1) {
        cost += c[j];
        rep(k, m) t[k] += a[j][k];
      }
    }
    rep(j, m) {
      if (t[j] < x)
        flag = false;
    }
    if (flag)
      ans = min(ans, cost);
  }
  if (ans == 9999999999999) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
using ll = long long;
int main() {
  int n, m, x;
  ll ans = 9999999999999;
  cin >> n >> m >> x;
  vector<int> c(n);
  int a[10010][10010];
  rep(i, n) {
    cin >> c[i];
    rep(j, m) cin >> a[i][j];
  }
  rep(i, 1 << n) {
    ll cost = 0;
    vector<ll> t(m);
    rep(j, m) t[j] = 0;
    bool flag = true;
    rep(j, n) {
      if (i >> j & 1) {
        cost += c[j];
        rep(k, m) t[k] += a[j][k];
      }
    }
    rep(j, m) {
      if (t[j] < x)
        flag = false;
    }
    if (flag)
      ans = min(ans, cost);
  }
  if (ans == 9999999999999) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
}
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N, M, X;
  cin >> N >> M >> X;
  vector<int> C(N);
  vector<vector<int>> A(N, vector<int>(M));
  for (int i = 0; i < N; i++) {
    cin >> C[i];
    for (int j = 0; j < M; j++) {
      cin >> A[i][j];
    }
  }
  int sum0 = 1200000;
  bool ans = false;
  for (int tmp = 1; tmp < (1 << 12); tmp++) {
    bitset<12> s(tmp);
    if (N != 12) {
      if (s.test(N))
        break;
    }
    vector<int> Adash(M);
    int sum1 = 0;
    for (int i = 0; i < 12; i++) {
      if (s.test(i)) {
        sum1 += C[i];
        for (int j = 0; j < M; j++) {
          Adash[j] += A[i][j];
        }
      }
    }
    bool ans1 = true;
    for (int j = 0; j < M; j++) {
      if (Adash[j] < X)
        ans1 = false;
    }
    if (ans1) {
      sum0 = min(sum0, sum1);
      ans = true;
    }
  }
  if (ans)
    cout << sum0 << endl;
  else
    cout << -1 << endl;
}


Error: 0

Fixed submission:

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

int main() {
  int N, M, X;
  cin >> N >> M >> X;
  vector<int> C(N);
  vector<vector<int>> A(N, vector<int>(M));
  for (int i = 0; i < N; i++) {
    cin >> C[i];
    for (int j = 0; j < M; j++) {
      cin >> A[i][j];
    }
  }
  int sum0 = 1200000;
  bool ans = false;
  for (int tmp = 1; tmp < (1 << 12); tmp++) {
    bitset<12> s(tmp);
    if (s.count() != 12 && s.test(N))
      break;
    vector<int> Adash(M);
    int sum1 = 0;
    for (int i = 0; i < 12; i++) {
      if (s.test(i)) {
        sum1 += C[i];
        for (int j = 0; j < M; j++) {
          Adash[j] += A[i][j];
        }
      }
    }
    bool ans1 = true;
    for (int j = 0; j < M; j++) {
      if (Adash[j] < X)
        ans1 = false;
    }
    if (ans1) {
      sum0 = min(sum0, sum1);
      ans = true;
    }
  }
  if (ans)
    cout << sum0 << endl;
  else
    cout << -1 << endl;
}
Problem p02683 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int a[12][12];
const int INF = 1001001001;

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  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];
  }

  int ans = INF;
  // 全ビット探索
  for (int s = 0; s < 1 << n; s++) {
    // cost 今までの本の総額
    // d 理解度
    int cost = 0;
    vector<int> d(m);

    for (int i = 0; i < n; i++) {
      // i番目の本を購入する場合
      if (s >> i & 1) {
        cost += c[i];
        for (int j = 0; j < m; j++)
          d[j] += a[i][j];
      }
    }
    bool ok = true;
    // アルゴリズムj番目の理解度がx未満なら判定を
    // falseにする
    for (int j = 0; j < m; j++)
      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 <iostream>
#include <vector>
using namespace std;

int a[12][12];
const int INF = 1001001001;

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  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];
  }

  int ans = INF;
  // 全ビット探索
  for (int s = 0; s < n; 1 << n) {
    // cost 今までの本の総額
    // d 理解度
    int cost = 0;
    vector<int> d(m);

    for (int i = 0; i < n; i++) {
      // i番目の本を購入する場合
      if (s >> i & 1) {
        cost += c[i];
        for (int j = 0; j < m; j++)
          d[j] += a[i][j];
      }
    }
    bool ok = true;
    // アルゴリズムj番目の理解度がx未満なら判定を
    // falseにする
    for (int j = 0; j < m; j++)
      if (d[j] < x)
        ok = false;
    if (ok)
      ans = min(ans, cost);
  }

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

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  int i = 0;
  int n, m, x;
  cin >> n >> m >> x;
  int a[n][m];
  int b[m];
  int c[n];
  memset(b, 0, sizeof(b));
  int j;
  for (i = 0; i < n; i++) {
    cin >> c[i];
    for (j = 0; j < m; j++)
      cin >> a[i][j];
  }
  i = 0;
  int d[n];
  int ans = INT_MAX;
  while (i < pow(2, n)) {
    memset(d, 0, sizeof(d));
    j = 0;
    int y = i;
    while (i) {
      d[j++] = i % 2;
      i /= 2;
    }
    int p = 0;
    memset(b, 0, sizeof(b));
    for (j = 0; j < n; j++) {
      if (d[j] == 1) {
        p += c[j];
        int q;
        for (q = 0; q < m; q++)
          b[q] += a[j][q];
      }
    }
    for (j = 0; j < m; j++)
      if (b[j] < x)
        break;
    if (j == m)
      ans = min(ans, p);
    i = y;
    i++;
    // cout<<i<<endl;
  }
  if (ans != INT_MAX)
    cout << ans << endl;
  else
    cout << -1 << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int ans = INT_MAX;
bool f(int b[], int m, int x) {
  int i;
  for (i = 0; i < m; i++) {
    // cout<<b[i]<<"POP"<<endl;
    if (b[i] < x)
      return 0;
  }
  return 1;
}
int fnc(int i, int n, int co, int m, int x, int a[][12], int c[], int b[]) {
  // cout<<i<<co<<f(b,m,x)<<endl;
  if (f(b, m, x) == 1)
    ans = min(ans, co);
  if (i == n)
    return 0;
  // cout<<i<<" "<<ans<<" "<<co<<" "<<endl;
  fnc(i + 1, n, co, m, x, a, c, b);
  int j = 0;
  int bb[m];
  for (j = 0; j < m; j++) {
    bb[j] = b[j] + a[i][j];
  }
  co += c[i];
  fnc(i + 1, n, co, m, x, a, c, bb);
}
int main() {
  int n, m, x;
  cin >> n >> m >> x;
  int c[n];
  int a[n][12];
  int i, j;
  for (i = 0; i < n; i++) {
    cin >> c[i];
    for (j = 0; j < m; j++)
      cin >> a[i][j];
  }
  int b[m];
  memset(b, 0, sizeof(b));
  fnc(0, n, 0, m, x, a, c, b);
  if (ans != INT_MAX)
    cout << ans << endl;
  else
    cout << -1 << endl;
  return 0;
}
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;

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

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

  for (int i = 0; i < n; i++) {
    cin >> c.at(i);
    for (int j = 0; j < m; j++) {
      cin >> table.at(i).at(j);
    }
  }
  int ans = INF;
  int all = 1 << n;
  for (int s = 0; s < all; s++) {
    vector<int> level(m);
    int cost = 0;

    for (int i = 0; i < n; i++) {
      if ((s >> i) & 1) {
        cost += c.at(i);
        for (int j = 0; j < m; j++) {
          level.at(j) += table.at(i).at(j);
        }
      }
    }
    bool ok = true;
    for (int j = 0; j < m; j++) {
      if (level.at(j) < x)
        ok = false;
    }
    if (ok)
      ans = min(ans, cost);
  }
  if (ans == INF) {
    cout << -1 << endl;
  } else
    cout << ans << endl;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;

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

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

  for (int i = 0; i < n; i++) {
    cin >> c.at(i);
    for (int j = 0; j < m; j++) {
      cin >> table.at(i).at(j);
    }
  }
  int ans = INF;

  for (int s = 0; s < (1 << n); s++) {
    int cost = 0;
    vector<int> d(m);

    for (int i = 0; i < n; i++) {
      if ((s >> i) & 1) {
        cost += c.at(i);
        for (int j = 0; j < m; j++) {
          d.at(i) += table.at(i).at(j);
        }
      }
    }
    bool ok = true;
    for (int j = 0; j < m; j++) {
      if (d.at(j) < x)
        ok = false;
    }
    if (ok)
      ans = min(ans, cost);
  }
  if (ans == INF) {
    cout << -1 << endl;
  } else
    cout << ans << endl;
}