alexjercan/bugnet huggingface dataset:
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> C(12);
  vector<vector<int>> pa(n, vector<int>(m));
  rep(i, n) {
    cin >> C.at(i);
    rep(j, m) { cin >> pa.at(i).at(j); }
  }
  int ans = 100100100;
  int count = 0;

  for (int tmp = 0; tmp < (1 << 12); tmp++) {
    bitset<12> s(tmp);
    // (ビット列sに対する処理)
    count = 0;
    vector<int> Ans(m);
    rep(i, n) {

      if (s.test(i)) {
        count += C.at(i);
        rep(j, m) { Ans.at(j) += pa.at(i).at(j); }
      }
    }
    bool can = true;
    rep(i, m) {
      if (Ans.at(i) < x) {
        can = false;
      }
    }
    if (can) {
      ans = min(count, ans);
    }
  }
  if (ans == 100100100) {
    cout << -1 << endl;
  } else
    cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> C(12);
  vector<vector<int>> pa(n, vector<int>(m));
  rep(i, n) {
    cin >> C.at(i);
    rep(j, m) { cin >> pa.at(i).at(j); }
  }
  int ans = 100100100;
  int count = 0;

  for (int tmp = 0; tmp < (1 << 12); tmp++) {
    bitset<12> s(tmp);
    // (ビット列sに対する処理)
    count = 0;
    vector<int> Ans(n);
    rep(i, n) {

      if (s.test(i)) {
        count += C.at(i);
        rep(j, m) { Ans.at(j) += pa.at(i).at(j); }
      }
    }
    bool can = true;
    rep(i, m) {
      if (Ans.at(i) < x) {
        can = false;
      }
    }
    if (can) {
      ans = min(count, ans);
    }
  }
  if (ans == 100100100) {
    cout << -1 << endl;
  } else
    cout << ans << endl;
}
Problem p02683 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;
using ll = long long;
using P = pair<int, int>;

int INF = 1 << 30;

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 book[12][12];

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

  rep(i, n) {
    cin >> price[i];
    rep(j, m) { cin >> book[i][j]; }
  }

  int result = INF;
  rep(s, 1 << n) {
    int cost = 0;

    vector<int> skill(m);
    rep(i, n) {
      if (s >> i & 1) {
        cost += price[i];
        rep(j, m) skill[j] += book[i][j];
      }
    }
    bool is_ok = true;
    rep(i, m) {
      if (skill[i] < x)
        is_ok = false;
    }
    if (is_ok) {
      result = min(result, cost);
    }
  }

  if (result == INF) {
    cout << -1 << endl;
  } else {
    cout << result << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;
using ll = long long;
using P = pair<int, int>;

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

struct book {
  int price;
  vector<int> v;
};

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<book> books;
  rep(i, n) {
    book b;
    cin >> b.price;
    vector<int> v;
    rep(j, m) {
      int a;
      cin >> a;
      v.push_back(a);
    }
    b.v = v;
    books.push_back(b);
  }

  vector<int> index;
  rep(i, n) { index.push_back(i); }

  int result = 1 << 30;
  do {
    vector<int> learn(m, 0);
    int sum = 0;
    for (int i : index) {
      book b = books[i];
      sum += b.price;
      bool isok = true;
      rep(j, m) {
        learn[j] += b.v[j];
        if (learn[j] < x)
          isok = false;
      }
      if (isok) {
        result = min(result, sum);
        break;
      }
    }

  } while (next_permutation(index.begin(), index.end()));
  if (result == 1 << 30) {
    cout << -1 << endl;
  } else {
    cout << result << endl;
  }
  return 0;
}
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>
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.at(i);
    for (int j = 0; j < m; ++j) {
      cin >> a.at(i).at(j);
    }
  }

  int ans = 1000000000;
  for (int i = 0; i <= (1 << n) - 1; ++i) {
    int sum_c = 0;
    vector<int> sum_a(m, 0);
    for (int j = 0; j < n; ++j) {
      if (i >> j & 1) {
        sum_c += c.at(j);
        for (int k = 0; k < m; ++k) {
          sum_a.at(k) += a.at(j).at(k);
        }
      }
    }
    bool f = true;
    for (int k = 0; k < m; ++k) {
      if (sum_a.at(k) < x) {
        f = false;
        break;
      }
    }
    if (f && sum_c < ans) {
      ans = sum_c;
    }
  }
  if (ans == 1000000000) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
#include <vector>
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.at(i);
    for (int j = 0; j < m; ++j) {
      cin >> a.at(i).at(j);
    }
  }

  int ans = 1000000000;
  for (int i = 0; i <= (1 << n) - 1; ++i) {
    int sum_c = 0;
    vector<int> sum_a(n, 0);
    for (int j = 0; j < n; ++j) {
      if (i >> j & 1) {
        sum_c += c.at(j);
        for (int k = 0; k < m; ++k) {
          sum_a.at(k) += a.at(j).at(k);
        }
      }
    }
    bool f = true;
    for (int k = 0; k < m; ++k) {
      if (sum_a.at(k) < x) {
        f = false;
        break;
      }
    }
    if (f && sum_c < ans) {
      ans = sum_c;
    }
  }
  if (ans == 1000000000) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <string.h>
using namespace std;
struct Node {
  int money;
  int a[15];
} book[15];
int b[15];
int main() {
  int n, m, x;
  cin >> n >> m >> x;
  for (int i = 0; i < n; i++) {
    cin >> book[i].money;
    for (int j = 0; j < m; j++)
      cin >> book[i].a[j];
  }
  int arr = 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].money;
        for (int k = 0; k < m; k++)
          b[k] += book[j].a[k];
      }
    }
    bool flag = 1;
    for (int k = 0; k < m; k++) {
      if (b[k] < x) {
        flag = 0;
        break;
      }
    }
    if (flag)
      arr = min(sum, arr);
  }
  if (arr == 2e9)
    cout << "-1";
  else
    cout << arr;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
struct node {
  int pri;
  int a[15];
} st[15];
int arr[10000];
int n, m, x, len = 0;
int sum[15];
bool sign[15];
int teil = 0;
int work() {
  int flag = 0;
  for (int i = 1; i <= m; i++) {
    if (sum[i] >= x)
      flag++;
  }
  return flag;
}
void dfs(int a) {
  if (work() == m) {
    teil = 1;
    arr[++len] = sum[0];
    return;
  }
  if (a > m)
    return;
  for (int i = 1; i <= n; i++) {
    if (!sign[i]) {
      sign[i] = 1;
      sum[0] += st[i].pri;
      for (int j = 1; j <= m; j++) {
        sum[j] += st[i].a[j];
      }
      dfs(a + 1);
      sign[i] = 0;
      sum[0] -= st[i].pri;
      for (int j = 1; j <= m; j++) {
        sum[j] -= st[i].a[j];
      }
    }
  }
}
bool cmp1(node a, node b) { return a.pri < b.pri; }
int main() {
  cin >> n >> m >> x;
  for (int i = 1; i <= n; i++) {
    cin >> st[i].pri;
    int flag = 0;
    for (int j = 1; j <= m; j++) {
      cin >> st[i].a[j];
      if (st[i].a[j] >= x)
        flag++;
    }
    if (flag == x)
      arr[++len] = st[i].pri;
  }
  sort(st + 1, st + 1 + n, cmp1);
  dfs(1);
  sort(arr + 1, arr + len + 1);
  if (teil == 1)
    cout << arr[1] << "\\n";
  else
    cout << -1 << "\\n";
  return 0;
}
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

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

#define ll long long
#define VI vector<int>
#define VL vector<ll>
#define PII pair<int, int>
#define VII vector<PII>
#define mp make_pair
#define pb push_back
#define vt vector
#define PI acos(-1)
#define ld long double
#define endl "\\n"
#define all(c) (c).begin(), (c).end()
#define ft first
#define sd second
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define F0R(i, b) for (int i = 0; i < b; ++i)
#define RF0R(i, b) for (int i = b; i >= 0; --i)
const ll inf = 1e18;
const int MxN = 100001;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n, m, x;
  cin >> n >> m >> x;
  vt<int> c(n);
  vt<vt<int>> A(n, vt<int>(m));

  F0R(i, n) {
    cin >> c[i];
    F0R(j, m)
    cin >> A[i][j];
  }
  int ans = INT_MAX;
  F0R(i, (1 << n)) {
    int cost = 0;
    vt<int> skills(m);
    F0R(j, n) {
      if ((i >> j) & 1) {
        // cout << 1 ;
        F0R(k, m)
        skills[k] += A[j][k];
        cost += c[j];
      }
      // cout <<0;
    }
    // cout << endl ;
    bool ok = true;
    F0R(j, m) {
      if (skills[j] < x) {
        ok = false;
        break;
      }
    }
    if (ok) {
      ans = min(ans, cost);
    }
  }
  if (ans == INT_MAX)
    cout << -1;
  else
    cout << ans;
  return 0;
}


Error: WA

Fixed submission:

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

#define ll long long
#define VI vector<int>
#define VL vector<ll>
#define PII pair<int, int>
#define VII vector<PII>
#define mp make_pair
#define pb push_back
#define vt vector
#define PI acos(-1)
#define ld long double
#define endl "\\n"
#define all(c) (c).begin(), (c).end()
#define ft first
#define sd second
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define F0R(i, b) for (int i = 0; i < b; ++i)
#define RF0R(i, b) for (int i = b; i >= 0; --i)
const ll inf = 1e18;
const int MxN = 100001;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n, m, x;
  cin >> n >> m >> x;
  vt<int> c(n);
  vt<vt<int>> A(n, vt<int>(m));

  F0R(i, n) {
    cin >> c[i];
    F0R(j, n)
    cin >> A[i][j];
  }
  int ans = INT_MAX;
  F0R(i, (1 << n)) {
    int cost = 0;
    vt<int> skills(m);
    F0R(j, n) {
      if ((i >> j) & 1) {
        // cout << 1 ;
        F0R(k, m)
        skills[k] += A[j][k];
        cost += c[j];
      }
      // cout <<0;
    }
    // cout << endl ;
    bool ok = true;
    F0R(j, m) {
      if (skills[j] < x) {
        ok = false;
        break;
      }
    }
    if (ok) {
      ans = min(ans, cost);
    }
  }
  if (ans == INT_MAX)
    cout << -1;
  else
    cout << ans;
  return 0;
}
Problem p02683 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define INF (1 << 30) - 1
#define LINF 1LL << 60
const int MOD = 1000000007;
using ll = long long;
using P = pair<int, int>;

int a[20][20];
int c[20];

int main() {
  int n, m, x;
  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 = INF;
  for (int b = 0; b < (1 << n); ++b) {
    vector<int> comprehension(m, 0);
    int cost = 0;
    for (int i = 0; i < n; ++i) {
      if ((b >> i) & 1) {
        cost += c[i];
        for (int j = 0; j < m; ++j) {
          comprehension[j] += a[i][j];
        }
      }
    }
    sort(comprehension.begin(), comprehension.end());
    if (comprehension[0] >= x)
      ans = min(ans, cost);
  }

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


Error: TLE

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define INF (1 << 30) - 1
#define LINF 1LL << 60
const int MOD = 1000000007;
using ll = long long;
using P = pair<int, int>;

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

  sort(sum.begin(), sum.end());
  if (sum[0] < x) {
    cout << -1 << endl;
    return 0;
  }

  vector<int> algo(m, 0);
  int ans = INF;
  do {
    int tmp = 0;
    int min_algo;
    vector<int> algo(m);
    for (int i = 0; i < n; ++i) {
      // tmp += a[perm[i]][0];
      tmp += c[perm[i]];
      min_algo = INF;
      for (int j = 0; j < m; ++j) {
        algo[j] += a[perm[i]][j];
        min_algo = min(min_algo, algo[j]);
      }
      if (min_algo >= x)
        break;
    }

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

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

#include <bits/stdc++.h>
#define Dim 1 << 14
using namespace std;
ifstream f("A.in");
typedef long long ll;
ll N, M, X, A[15], P[15], x, ans = -1, cost;
ll dp[Dim], L[Dim][15];
bool viz[15];
vector<ll> V[15];
vector<ll> dq;

int main() {
  cin >> N >> M >> X;
  for (int i = 0; i < N; i++) {
    cin >> P[i];
    V[i].push_back(0);
    for (int j = 1; j <= M; j++) {
      cin >> x;
      V[i].push_back(x);
    }
  }
  for (int i = 0; i < (1 << N); i++) {
    int lg = log2(i) + 1;
    cost = 0;
    for (int k = 0; k <= lg; k++)
      if ((i & (1 << k)) > 0) {
        cost += P[k];
        for (int j = 1; j <= M; j++)
          L[i][j] += V[k][j];
      }

    bool stop = 0;
    for (int j = 1; j <= M && stop == 0; j++)
      if (L[i][j] < X)
        stop = 1;

    if (stop == 0) {
      if (ans == -1)
        ans = cost;
      else if (cost < ans)
        ans = cost;
    }
  }
  cout << ans;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
ifstream f("A.in");
typedef long long ll;
ll N, M, X, A[15], P[15], x, ans = -1, L[15], cost;
bool viz[15];
vector<ll> V[15];
vector<ll> dq;

void BKT(int lgcur, int lg) {
  if (lgcur == lg + 1) {
    for (int i = 0; i < lg; i++) {
      for (int j = 1; j <= M; j++)
        L[j] += V[dq[i]][j];
    }
    bool stop = 0;
    for (int i = 1; i <= M && stop == 0; i++)
      if (L[i] < X)
        stop = 1;
    for (int i = 1; i <= M; i++)
      L[i] = 0;
    if (stop == 0) {

      if (ans == -1)
        ans = cost;
      else if (cost < ans)
        ans = cost;
    }
  }
  for (int i = 1; i <= N; i++)
    if (!viz[i]) {
      viz[i] = 1;
      cost += P[i];
      dq.push_back(i);
      BKT(lgcur + 1, lg);
      cost -= P[i];
      viz[i] = 0;
      dq.pop_back();
    }
}

int main() {
  cin >> N >> M >> X;
  for (int i = 1; i <= N; i++) {
    cin >> P[i];
    V[i].push_back(0);
    for (int j = 1; j <= M; j++) {
      cin >> x;
      V[i].push_back(x);
    }
  }

  for (int k = 0; k <= N; k++)
    BKT(1, k);
  cout << ans;
  return 0;
}
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define Sort(a) sort(a.begin(), a.end())
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

const int INF = 1 << 30;

int n, m, x;
int min_ = INF;
int c[15];
int a[15][15];

void dfs(vector<int> &A) {
  int len = A.size();
  if (len == n) {
    ll sum = 0;
    vi f(m, 0);
    bool flag = true;
    rep(i, len) {
      if (A.at(i) == 1) {
        sum += c[i];
        rep(j, m) f[j] += a[i][j];
      }
    }
    rep(j, m) {
      if (f[j] < x)
        flag = false;
    }
    if (sum <= min_ && flag)
      min_ = sum;
    return;
  }
  for (int v = 0; v < 2; ++v) {
    A.push_back(v);
    dfs(A);
    A.pop_back();
  }
}

int main() {
  cin >> n >> m >> x;
  vi f(m, 0);
  rep(i, n) {
    cin >> c[i];
    rep(j, m) {
      cin >> a[i][j];
      f[j] += a[i][j];
    }
  }
  rep(i, m) {
    if (f[i] < x) {
      cout << -1 << endl;
      return 0;
    }
  }
  vector<int> A;
  dfs(A);
  cout << min_ << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define Sort(a) sort(a.begin(), a.end())
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

const int INF = 1 << 30;

int n, m, x;
int min_ = INF;
int c[15];
int a[15][15];

void dfs(vector<int> &A) {
  int len = A.size();
  if (len == n) {
    ll sum = 0;
    vi f(n, 0);
    bool flag = true;
    rep(i, len) {
      if (A.at(i) == 1) {
        sum += c[i];
        rep(j, m) f[j] += a[i][j];
      }
    }
    rep(j, m) {
      if (f[j] < x)
        flag = false;
    }
    if (sum <= min_ && flag)
      min_ = sum;
    return;
  }
  for (int v = 0; v < 2; ++v) {
    A.push_back(v);
    dfs(A);
    A.pop_back();
  }
}

int main() {
  cin >> n >> m >> x;
  vi f(m, 0);
  rep(i, n) {
    cin >> c[i];
    rep(j, m) {
      cin >> a[i][j];
      f[j] += a[i][j];
    }
  }
  rep(i, m) {
    if (f[i] < x) {
      cout << -1 << endl;
      return 0;
    }
  }
  vector<int> A;
  dfs(A);
  cout << min_ << endl;
  return 0;
}
Problem p02683 (C++) — buggy submission, verdict: Time Limit Exceeded


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

int N, M, X;
int num = 0;
int C[12], A[12][12];
int dp[12];
long anss;
long ans = 0;
bool visited[12];

void mnis(int X, int x) {
  if (visited[x])
    return;
  bool caan = true;
  for (int i = 0; i < M; i++)
    dp[i] -= A[x][i];
  for (int i = 0; i < M; i++)
    if (dp[i] < X)
      caan = false;
  if (caan) {
    visited[x] = true;
    ans -= C[x];
    anss = min(anss, ans);
    for (int i = x; i < N; i++)
      mnis(X, i);
    for (int i = 0; i < M; i++)
      dp[i] += A[x][i];
    visited[x] = false;
    ans += C[x];
  } else {
    for (int i = 0; i < M; i++)
      dp[i] += A[x][i];
  }
  return;
}

int main() {
  bool able = true;
  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];
  }
  for (int i = 0; i < M; i++)
    dp[i] = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      dp[j] += A[i][j];
    }
  }
  for (int i = 0; i < N; i++)
    ans += C[i];
  anss = ans;
  for (int i = 0; i < M; i++)
    if (dp[i] < X)
      able = false;
  for (int i = 0; i < N; i++)
    mnis(X, i);
  if (able)
    cout << anss << endl;
  else
    cout << "-1" << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

int N, M, X;
int num = 0;
int C[12], A[12][12];
int dp[12];
long anss;
long ans = 0;
bool visited[12];

void mnis(int X, int x) {
  if (visited[x])
    return;
  bool caan = true;
  for (int i = 0; i < M; i++)
    dp[i] -= A[x][i];
  for (int i = 0; i < M; i++)
    if (dp[i] < X)
      caan = false;
  if (caan) {
    visited[x] = true;
    ans -= C[x];
    anss = min(anss, ans);
    for (int i = 0; i < N; i++)
      mnis(X, i);
    for (int i = 0; i < M; i++)
      dp[i] += A[x][i];
    visited[x] = false;
    ans += C[x];
  } else {
    for (int i = 0; i < M; i++)
      dp[i] += A[x][i];
  }
  return;
}

int main() {
  bool able = true;
  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];
  }
  for (int i = 0; i < M; i++)
    dp[i] = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      dp[j] += A[i][j];
    }
  }
  for (int i = 0; i < N; i++)
    ans += C[i];
  anss = ans;
  for (int i = 0; i < M; i++)
    if (dp[i] < X)
      able = false;
  for (int i = 0; i < N; i++)
    mnis(X, i);
  if (able)
    cout << anss << endl;
  else
    cout << "-1" << 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)
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: 0

Fixed submission:

#include <bits/stdc++.h>
#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][n];
  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;
}