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

#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

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

int main() {
  ll n, m, x;
  cin >> n >> m >> x;
  vector<int> C(n);
  vector<vector<ll>> A(n, vector<ll>(m));

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

  /*for (int i = 1; i < m; i++) {
          if (std::accumulate(A[i].begin(), A[i].end(), 0) < x) {
                  cout << -1;
                  return 0;
          }
  }*/

  ll ans = 1e8;
  for (int i = 0; i < 1 << n; i++) {
    ll cost = 0;
    vector<int> d(m);
    for (int j = 0; j < n; j++) {
      if (i >> j & 1) {
        cost += C[j];
        for (int k = 0; k < m; k++)
          d[k] += A[j][k];
      }
    }
    bool flag = true;

    for (int j = 0; j < m; j++) {
      if (d[j] < x) {
        flag = false;
      }
    }
    if (flag)
      ans = std::min(ans, cost);
  }
  if (ans == 1e8)
    cout << -1 << endl;
  else
    cout << ans;

  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

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

int main() {
  ll n, m, x;
  cin >> n >> m >> x;
  vector<int> C(n);
  vector<vector<ll>> A(n, vector<ll>(m));

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

  for (int i = 1; i < m; i++) {
    if (std::accumulate(A[i].begin(), A[i].end(), 0) < x) {
      cout << -1;
      return 0;
    }
  }

  ll ans = 1e8;
  for (int i = 0; i < 1 << n; i++) {
    ll cost = 0;
    vector<int> d(m);
    for (int j = 0; j < n; j++) {
      if (i >> j & 1) {
        cost += C[j];
        for (int k = 0; k < m; k++)
          d[k] += A[j][k];
      }
    }
    bool flag = true;

    for (int j = 0; j < m; j++) {
      if (d[j] < x) {
        flag = false;
      }
    }
    if (flag)
      ans = std::min(ans, cost);
  }
  if (ans == 1e8)
    cout << -1 << endl;
  else
    cout << ans;

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

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>

using namespace std;

vector<int> IntegerToVerctor(int bit, long long N) {
  vector<int> S;
  for (int i = 0; i < N; ++i) {
    if (bit & (1 << i)) {
      S.push_back(i);
    }
  }
  return S;
}

int main() {
  long long N, M, X;
  cin >> N >> M >> X;
  vector<long long> C(20);
  vector<vector<long long>> A(20, vector<long long>(20));
  for (int i = 1; i <= N; i++) {
    cin >> C[i];
    for (int j = 1; j <= M; j++) {
      cin >> A[i][j];
    }
  }
  long long mincost = 100000000;
  long long cost;
  bool flag;
  vector<int> sum(20);
  for (int bit = 0; bit < (1 << N); ++bit) {
    cost = 0;
    flag = 1;
    for (int j = 1; j <= M; j++) {
      sum[j] = 0;
    }
    vector<int> S = IntegerToVerctor(bit, N);
    for (int i : S) {
      cost += C[i + 1];
      for (int j = 1; j <= M; j++) {
        sum[j] += A[i + 1][j];
      }
    }
    for (int i = 1; i <= M; i++) {
      if (sum[i] < X) {
        flag = 0;
        break;
      }
    }
    if (flag == 1) {
      mincost = min(cost, mincost);
    }
  }

  if (mincost == 100000000) {
    cout << -1 << endl;
  } else {
    cout << mincost << endl;
  }

  return 0;
}


Error: 0

Fixed submission:

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>

using namespace std;

vector<int> IntegerToVerctor(int bit, long long N) {
  vector<int> S;
  for (int i = 0; i < N; ++i) {
    if (bit & (1 << i)) {
      S.push_back(i);
    }
  }
  return S;
}

int main() {
  long long N, M, X;
  cin >> N >> M >> X;
  vector<long long> C(N + 1);
  vector<vector<long long>> A(N + 1, vector<long long>(M + 1));
  for (int i = 1; i <= N; i++) {
    cin >> C[i];
    for (int j = 1; j <= M; j++) {
      cin >> A[i][j];
    }
  }
  long long mincost = 100000000;
  long long cost;
  bool flag;
  vector<int> sum(N + 1);
  for (int bit = 0; bit < (1 << N); ++bit) {
    cost = 0;
    flag = 1;
    for (int j = 1; j <= M; j++) {
      sum[j] = 0;
    }
    vector<int> S = IntegerToVerctor(bit, N);
    for (int i : S) {
      cost += C[i + 1];
      for (int j = 1; j <= M; j++) {
        sum[j] += A[i + 1][j];
      }
    }
    for (int i = 1; i <= M; i++) {
      if (sum[i] < X) {
        flag = 0;
        break;
      }
    }
    if (flag == 1) {
      mincost = min(cost, mincost);
    }
  }

  if (mincost == 100000000) {
    cout << -1 << endl;
  } else {
    cout << mincost << endl;
  }

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

#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
struct node {
  int c;     // 每本书的价格
  int a[15]; // 这本书能够提升Ta的第j个算法多少等级
} book[15];  // 储存每一本书的信息
int b[15];   // 统计每个子集能够提升第j个算法的总的等级数
int main() {
  int n, m, x;
  cin >> n >> m >> x;
  for (int i = 0; i < n; i++) {
    cin >> book[i].c;
    for (int j = 0; j < m; j++)
      cin >> book[i].a[j];
  }
  int ans = 2e9;
  for (int i = 0; i < (1 << n); i++) {
    memset(b, 0, sizeof b);
    int sum = 0; // 统计每一个子集所有书的总价格
    for (int j = 0; j < n; j++)
      if (i >> j & 1) {
        sum += book[j].c;
        for (int k = 0; k < m; k++)
          b[k] += book[j].a[k];
      }
    bool flag = 1; // 判断m个算法是否都大于等于x，1为是，0为否
    for (int j = 0; j < m; j++)
      if (b[j] < x)
        flag = 0;
    if (flag)
      ans = min(ans, sum); // 每次都选择更小价格
  }
  if (ans == 2e9)
    cout << "-1";
  else
    cout << ans;
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
struct node {
  int pri;
  int a[18];
} st[18];
int ans = 1e8;
int b[18];
int d[18];
int n, m, x;
int len;
int dfs(int p) {
  if (p == len + 1) {
    int sum = 0;
    memset(d, 0, sizeof(d));
    for (int i = 1; i <= len; i++) {
      sum += st[b[i]].pri;
      for (int j = 1; j <= m; j++) {
        d[j] += st[b[i]].a[j];
      }
    }
    for (int i = 1; i <= m; i++) {
      if (d[i] < x)
        return 0;
    }
    ans = min(ans, sum);
    return 0;
  }
  for (int i = b[p - 1] + 1; i <= n; i++) {
    b[p] = i;
    dfs(p + 1);
  }
}
int main() {
  cin >> n >> m >> x;
  for (int i = 1; i <= n; i++) {
    cin >> st[i].pri;
    for (int j = 1; j <= m; j++) {
      cin >> st[i].a[j];
    }
  }
  for (len = 1; len <= n; len++) {
    b[0] = 0;
    dfs(1);
  }
  if (ans == 1e8)
    cout << -1 << "\\n";
  else
    cout << ans << "\\n";
  return 0;
}
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

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

int main() {

  lint N, M, X;
  cin >> N >> M >> X;

  vector<lint> C(N);
  vector<vector<lint>> A(N, vector<lint>(M));
  vector<vector<lint>> rikai(pow(2, N), vector<lint>(M));
  vector<lint> price(pow(2, N));
  vector<bool> able(pow(2, N), false);

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

  // priceとrikaiを計算
  for (lint i = 1; i <= pow(2, N); i++) {
    lint tmp = i;
    for (lint j = 0; j < N; j++) {

      price[i - 1] += (tmp % 2) * C[j];

      for (lint k = 0; k < M; k++) {
        rikai[i - 1][k] += (tmp % 2) * A[j][k];
      }

      tmp = tmp / 2;
    }
  }

  // able判定
  for (lint i = 0; i < pow(2, N); i++) {
    sort(rikai[i].begin(), rikai[i].end());
    if (rikai[i][0] >= X)
      able[i] = true;
  }

  vector<lint> price_sort(0);

  for (int i = 0; i < pow(2, N); i++) {
    if (able[i])
      price_sort.push_back(price[i]);
  }

  if (price_sort.size() == 0)
    cout << "-1" << endl;
  else {
    sort(price_sort.begin(), price_sort.end());
    cout << price_sort[0] << endl;
  }
}


Error: 0

Fixed submission:

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

int main() {

  lint N, M, X;
  cin >> N >> M >> X;

  vector<lint> C(N);
  vector<vector<lint>> A(N, vector<lint>(M));
  vector<vector<lint>> rikai(pow(2, N), vector<lint>(M));
  vector<lint> price(pow(2, N));
  vector<bool> able(pow(2, N), false);

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

  // priceとrikaiを計算
  for (lint i = 1; i <= pow(2, N); i++) {
    lint tmp = i;
    for (lint j = 0; j < N; j++) {

      price[i - 1] += (tmp % 2) * C[j];

      for (lint k = 0; k < M; k++) {
        rikai[i - 1][k] += (tmp % 2) * A[j][k];
      }

      tmp = tmp / 2;
    }
  }

  // able判定
  for (lint i = 0; i < pow(2, N); i++) {
    sort(rikai[i].begin(), rikai[i].end());
    if (rikai[i][0] >= X)
      able[i] = true;
  }

  vector<lint> price_sort(0);

  for (int i = 0; i < pow(2, N); i++) {
    if (able[i])
      price_sort.push_back(price[i]);
  }

  if (price_sort.size() == 0)
    cout << -1 << endl;

  sort(price_sort.begin(), price_sort.end());

  cout << price_sort[0] << endl;
}
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2020 Bjarni Dagur Thor Karason

#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (__typeof(a) i = (a); i < (b); i++)
#define MP make_pair
#define PB push_back
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
#define INF 1000000000
#define PI 3.14159265359

int n, m, x, ans = INF;
vi cost, vals[13], cur;

bool valid() {
  for (auto u : cur) {
    if (u < x)
      return false;
  }
  return true;
}

void dp(int at, int spent) {
  if (valid()) {
    ans = min(ans, spent);
    return;
  }
  if (at == n)
    return;
  for (int i = 0; i < m; i++) {
    cur[i] += vals[at][i];
  }
  dp(at + 1, spent + cost[at]);
  for (int i = 0; i < m; i++) {
    cur[i] -= vals[at][i];
  }
  dp(at + 1, spent);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> m >> x;
  cost.resize(n);
  cur.resize(m, 0);
  for (int i = 0; i < n; i++) {
    cin >> cost[i];
    for (int j = 0; j < m; j++) {
      int in;
      cin >> in;
      vals[i].PB(in);
    }
  }
  dp(0, 0);
  cout << (ans == INF ? -1 : ans) << endl;

  return 0;
}

Error: 0

Fixed submission:

// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2020 Bjarni Dagur Thor Karason

#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (__typeof(a) i = (a); i < (b); i++)
#define MP make_pair
#define PB push_back
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
#define INF 1000000000
#define PI 3.14159265359

int n, m, x, ans = INF;
vi cost, vals[13], cur;

bool valid() {
  for (auto u : cur) {
    if (u < x)
      return false;
  }
  return true;
}

void dp(int at, int spent) {
  if (valid()) {
    ans = min(ans, spent);
    return;
  }
  if (at == n)
    return;
  for (int i = 0; i < m; i++) {
    cur[i] += vals[at][i];
  }
  dp(at + 1, spent + cost[at]);
  for (int i = 0; i < m; i++) {
    cur[i] -= vals[at][i];
  }
  dp(at + 1, spent);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> m >> x;
  cost.resize(m);
  cur.resize(m, 0);
  for (int i = 0; i < n; i++) {
    cin >> cost[i];
    for (int j = 0; j < m; j++) {
      int in;
      cin >> in;
      vals[i].PB(in);
    }
  }
  dp(0, 0);
  cout << (ans == INF ? -1 : ans) << 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 ll = long long;
using namespace std;

int main(void) {
  int N, M, X;
  cin >> N >> M >> X;
  int C[N];
  int A[N][M];
  rep(i, N) {
    cin >> C[i];
    rep(j, M) cin >> A[i][j];
  }

  ll cost_min = 0;
  rep(i, N) cost_min += C[i];

  int buy_all = 0;
  int k = 1;
  rep(i, N) {
    buy_all += k;
    k *= 2;
  }

  int mast_all = 1;
  ll und[M];

  for (int i = 0; i <= buy_all; i++) {
    rep(j, M) und[j] = 0;
    ll cost = 0;

    rep(j, N) {
      if (i >> j & 1) {
        cost += C[j];
        rep(k, M) und[k] += A[j][k];
      }
    }

    mast_all = 1;
    rep(j, M) {
      if (und[j] < X) {
        mast_all = 0;
        break;
      }
    }
    if (mast_all == 1 && cost <= cost_min)
      cost_min = cost;
  }

  if (mast_all == 0)
    cout << -1 << endl;
  else
    cout << cost_min << endl;

  return 0;
}


Error: 0

Fixed submission:

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

int main(void) {
  int N, M, X;
  cin >> N >> M >> X;
  int C[M + 5];
  int A[N + 5][M + 5];
  rep(i, N) {
    cin >> C[i];
    rep(j, M) cin >> A[i][j];
  }

  ll cost_min = 0;
  rep(i, N) cost_min += C[i];

  int buy_all = 0;
  int k = 1;
  rep(i, N) {
    buy_all += k;
    k *= 2;
  }

  int mast_all = 1;
  ll und[M + 5];

  for (int i = 0; i <= buy_all; i++) {
    rep(j, M) und[j] = 0;
    ll cost = 0;

    rep(j, N) {
      if (i >> j & 1) {
        cost += C[j];
        rep(k, M) und[k] += A[j][k];
      }
    }

    mast_all = 1;
    rep(j, M) {
      if (und[j] < X) {
        mast_all = 0;
        break;
      }
    }
    if (mast_all == 1 && cost <= cost_min)
      cost_min = cost;
  }

  if (mast_all == 0)
    cout << -1 << endl;
  else
    cout << cost_min << endl;

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

#include <bits/stdc++.h>
using namespace std;
int n, m, x;
int ans = INT_MAX;
vector<int> xx;
void subset(vector<vector<int>> &v, int ind, int &c) {
  if (ind >= n) {
    return;
  }
  subset(v, ind + 1, c);
  c += v[ind][0];
  int ok = 1;
  for (int i = 1; i <= m; i++) {
    xx[i - 1] += v[ind][i];
    if (xx[i - 1] < x)
      ok = 0;
  }
  if (ok) {
    ans = min(ans, c);
  } else {
    subset(v, ind + 1, c);
  }
  for (int i = 1; i <= m; i++) {
    xx[i - 1] -= v[ind][i];
  }
  c -= v[ind][0];
  return;
}

int main() {
  cin >> n >> m >> x;
  xx.resize(m);
  vector<vector<int>> v(n, vector<int>(m + 1, 0));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m + 1; j++) {
      cin >> v[i][j];
    }
  }
  int c = 0;
  subset(v, 0, c);
  if (ans == INT_MAX) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }

  return 0;
}


Error: 120

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int n, m, x;
int ans = INT_MAX;
vector<int> xx;
void subset(vector<vector<int>> &v, int ind, int &c) {
  if (ind >= n) {
    return;
  }
  subset(v, ind + 1, c);
  c += v[ind][0];
  int ok = 1;
  for (int i = 1; i <= m; i++) {
    xx[i - 1] += v[ind][i];
    if (xx[i - 1] < x)
      ok = 0;
  }
  if (ok) {
    ans = min(ans, c);
  } else {
    subset(v, ind + 1, c);
  }
  for (int i = 1; i <= m; i++) {
    xx[i - 1] -= v[ind][i];
  }
  c -= v[ind][0];
  return;
}
int main() {
  cin >> n >> m >> x;
  xx.resize(m);
  vector<vector<int>> v(n, vector<int>(m + 1, 0));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m + 1; j++) {
      cin >> v[i][j];
    }
  }
  int c = 0;
  subset(v, 0, c);
  if (ans == INT_MAX) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }

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

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

constexpr int MAX = 1e9;

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 ans = MAX;
  int l = 1 << n;
  for (int mask = 0; mask < l; ++mask) {
    vector<int> u(m, 0);
    int cost = 0;
    for (int i = 0; i < n; ++i) {
      if ((mask >> i) & 1) {
        cost += c[i];
        for (int j = 0; j < m; ++j) {
          u[j] += a[i][j];
        }
      }
    }

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

    if (ok && cost < ans) {
      ans = cost;
    }
  }

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

  return 0;
}

Error: TLE

Fixed submission:

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

int n, m, x;
int c[12];
int a[12][12];
int u[12];

constexpr int MAX = 1e9;

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

  return true;
}

void add(int b) {
  for (int i = 0; i < m; ++i) {
    u[i] += a[b][i];
  }
}

void rm(int b) {
  for (int i = 0; i < m; ++i) {
    u[i] -= a[b][i];
  }
}

int f(int mask, int s = 0) {
  if (ok()) {
    return s;
  }

  int mn = 1e9;
  for (int i = 0; i < n; ++i) {
    if ((mask >> i) & 1) {
      continue;
    }

    mask += (1 << i);
    add(i);
    mn = min(mn, f(mask, s + c[i]));
    rm(i);
    mask -= (1 << i);
  }

  return mn;
}

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

  for (int i = 0; i < m; ++i) {
    u[i] = 0;
  }

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

  if (!ok()) {
    cout << -1;
    return 0;
  }

  for (int i = 0; i < m; ++i) {
    u[i] = 0;
  }

  int ans = f(0);
  if (ans == MAX) {
    cout << -1;
  } else {
    cout << ans;
  }

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

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

int n, m, x;
int c[12];
int a[12][12];
int u[12];
int dp[4096];

constexpr int MAX = 1e9;

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

  return true;
}

void add(int b) {
  for (int i = 0; i < m; ++i) {
    u[i] += a[b][i];
  }
}

void rm(int b) {
  for (int i = 0; i < m; ++i) {
    u[i] -= a[b][i];
  }
}

int f(int mask, int s = 0) {
  if (ok()) {
    return s;
  }

  if (dp[mask] != MAX) {
    return dp[mask];
  }

  int mn = 1e9;
  for (int i = 0; i < n; ++i) {
    if ((mask >> i) & 1) {
      continue;
    }

    mask += (1 << i);
    add(i);
    mn = min(mn, f(mask, s + c[i]));
    dp[mask] = min(dp[mask], mn);
    rm(i);
    mask -= (1 << i);
  }

  return mn;
}

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

  for (int i = 0; i < m; ++i) {
    u[i] = 0;
  }

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

  if (!ok()) {
    cout << -1;
    return 0;
  }

  for (int i = 0; i < 4096; ++i) {
    dp[i] = MAX;
  }

  for (int i = 0; i < m; ++i) {
    u[i] = 0;
  }

  int ans = f(0);
  if (ans == MAX) {
    cout << -1;
  } else {
    cout << ans;
  }

  return 0;
}

Error: TLE

Fixed submission:

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

int n, m, x;
int c[12];
int a[12][12];
int u[12];
int dp[4096];

constexpr int MAX = 1e9;

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

  return true;
}

void add(int b) {
  for (int i = 0; i < m; ++i) {
    u[i] += a[b][i];
  }
}

void rm(int b) {
  for (int i = 0; i < m; ++i) {
    u[i] -= a[b][i];
  }
}

int f(int mask, int s = 0) {
  if (ok()) {
    return s;
  }

  if (dp[mask] != MAX) {
    return dp[mask];
  }

  int mn = 1e9;
  for (int i = 0; i < n; ++i) {
    if ((mask >> i) & 1) {
      continue;
    }

    mask += (1 << i);
    add(i);
    mn = min(mn, f(mask, s + c[i]));
    dp[mask] = min(dp[mask], mn);
    rm(i);
    mask -= (1 << i);
  }

  return mn;
}

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

  for (int i = 0; i < 4096; ++i) {
    dp[i] = MAX;
  }

  for (int i = 0; i < m; ++i) {
    u[i] = 0;
  }

  int ans = f(0);
  if (ans == MAX) {
    cout << -1;
  } else {
    cout << ans;
  }

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

int mini = 9999999;
int n, m, x;
vector<vector<int>> v(1, vector<int>(1));

bool check_x(vector<int> v, int x) {
  for (int i = 1; i < v.size(); i++) {
    if (v[i] < x)
      return false;
  }
  return true;
}

// 全購入パターンを作る
// 現在の参照番号num,現在のスキル合計配列v,
bool judge(int num, vector<int> sum) {
  // 終了チェック
  if (num == n) {
    // 条件チェック
    if (check_x(sum, x)) {
      // 最小更新
      if (sum[0] < mini) {
        mini = sum[0];
      }
    }
    return false;
  }

  // i番目を追加しない
  if (judge(num + 1, sum))
    return true;

  // i番目を追加する
  rep(j, m + 1) sum[j] += v[num][j];
  if (judge(num + 1, sum))
    return true;

  // 終了
  return false;
}

int main() {
  cin >> n >> m >> x;
  // 総当たりで調べる(max2^12)
  // vector<vector<int>> v(m+1,vector<int> (n));v[n][m+1]
  v.resize(n);
  for (size_t i = 0; i < n; i++) {
    v[i].resize(m + 1);
  }
  rep(i, n) {
    rep(j, m + 1) { cin >> v[i][j]; }
  }

  // 総和
  vector<int> tot(m + 1);
  rep(i, n) {
    rep(j, m + 1) { tot[j] += v[i][j]; }
  }
  if (!check_x(tot, x)) {
    cout << "-1" << endl;
    return 0;
  }

  // 最小探索
  vector<int> sum(m + 1);
  if (judge(0, sum)) {
    cout << "gg";
  }
  cout << mini << endl;
  return 0;
}


Error: -11

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 mini = 9999999;
int n, m, x;
vector<vector<int>> v(1, vector<int>(1));

bool check_x(vector<int> v, int x) {
  for (int i = 1; i < v.size(); i++) {
    if (v[i] < x)
      return false;
  }
  return true;
}

// 全購入パターンを作る
// 現在の参照番号num,現在のスキル合計配列v,
bool judge(int num, vector<int> sum) {
  // 終了チェック
  if (num == m + 1) {
    // 条件チェック
    if (check_x(sum, x)) {
      // 最小更新
      if (sum[0] < mini) {
        mini = sum[0];
      }
    }
    return false;
  }

  // i番目を追加しない
  if (judge(num + 1, sum))
    return true;

  // i番目を追加する
  rep(j, m + 1) { sum[j] += v[num][j]; }
  if (judge(num + 1, sum))
    return true;

  // 終了
  return true;
}

int main() {
  cin >> n >> m >> x;
  // 総当たりで調べる(max2^12)
  // vector<vector<int>> v(m+1,vector<int> (n));
  v.resize(m + 1);
  for (size_t i = 0; i < n; i++) {
    v[i].resize(n);
  }
  rep(i, n) {
    rep(j, m + 1) { cin >> v[i][j]; }
  }

  // 総和
  vector<int> tot(m + 1);
  rep(i, n) {
    rep(j, m + 1) { tot[j] += v[i][j]; }
  }
  if (!check_x(tot, x)) {
    cout << "-1" << endl;
    return 0;
  }

  // 最小探索
  vector<int> sum(m + 1);
  if (judge(1, sum))

    rep(i, n) {
      rep(j, m + 1) { cout << v[i][j] << " "; }
      cout << endl;
    }

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

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

int main() {
  long long cost = pow(10, 7);
  long long n, m, x;
  cin >> n >> m >> x;
  vector<vector<long long>> book(n, vector<long long>(m + 1));
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m + 1; j++)
      cin >> book[i][j];
  }
  for (long long i = 1; i <= (1 << n); i++) {
    long long total = 0;
    vector<long long> val(m);
    for (long long j = 0; j < n; j++) {
      if (i & (1 << j)) {
        total += book[j][0];
        for (long long k = 0; k < m; k++)
          val[k] += book[j][k + 1];
      }
    }
    bool flag = 1;
    for (long long j = 0; j < m; j++) {
      if (val[j] < x) {
        flag = 0;
        break;
      }
    }
    if (flag)
      cost = min(cost, total);
  }
  if (cost == pow(10, 7))
    cout << -1;
  else
    cout << cost;
  return 0;
}

Error: WA

Fixed submission:

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

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<vector<int>> book(n, vector<int>(m + 1));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++)
      cin >> book[i][j];
  }
  long long cost = 1e18;
  for (int i = 1; i < (1 << n); i++) {
    long long total = 0;
    vector<long long> val(m);
    for (int j = 0; j < n; j++) {
      if (i & (1 << j)) {
        total += book[j][0];
        for (int k = 0; k < m; k++)
          val[k] += book[j][k + 1];
      }
    }
    bool flag = 0;
    for (int j = 0; j < m; j++) {
      if (val[j] < x) {
        flag = 0;
        break;
      }
    }
    if (flag)
      cost = min(cost, total);
  }
  if (cost == 1e18)
    cout << -1;
  else
    cout << cost;
  return 0;
}