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

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

#define PI 3.14159265358
typedef long long ll;
typedef long double ld;

int main() {
  int n, m, x, ans = 1000000000, i, j;
  cin >> n >> m >> x;
  vector<vector<int>> set(n, vector<int>(m));
  vector<int> skills(m), cost(m);
  for (i = 0; i < n; i++) {
    cin >> cost[i];
    for (j = 0; j < m; j++) {
      cin >> set[i][j];
      skills[j] = 0;
    }
  }
  int se = 1 << n;
  int t = 0;
  for (int mask = 0; mask < se; mask++) {
    t = 0;
    for (i = 0; i < n; i++) {
      if ((mask >> i) & 1) {
        t += cost[i];
        for (j = 0; j < m; j++) {
          skills[j] += set[i][j];
        }
      }
    }
    bool ok = true;
    for (j = 0; j < m; j++) {
      if (skills[j] < x) {
        ok = false;
      }
      skills[j] = 0;
    }
    if (ok) {
      ans = min(ans, t);
    }
  }
  if (ans == 1000000000) {
    cout << -1 << "\\n";
  } else
    cout << ans << "\\n";

  return 0;
}


Error: 0

Fixed submission:

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

#define PI 3.14159265358
typedef long long ll;
typedef long double ld;

int main() {
  int n, m, x, ans = 1000000, i, j;
  cin >> n >> m >> x;
  int cost[m];
  int set[n][m];
  int skills[m];
  for (i = 0; i < n; i++) {
    cin >> cost[i];
    for (j = 0; j < m; j++) {
      cin >> set[i][j];
      skills[j] = 0;
    }
  }
  int se = 1 << n;
  int t = 0;
  for (int mask = 0; mask < se; mask++) {
    t = 0;
    for (i = 0; i < n; i++) {
      if ((mask >> i) & 1) {
        t += cost[i];
        for (j = 0; j < m; j++) {
          skills[j] += set[i][j];
        }
      }
    }
    bool ok = true;
    for (j = 0; j < m; j++) {
      if (skills[j] < x) {
        ok = false;
      }
      skills[j] = 0;
    }
    if (ok) {
      ans = min(ans, t);
    }
  }
  if (ans == 1000000) {
    cout << -1 << "\\n";
  } else
    cout << ans << "\\n";

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

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln = '\\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> b_val(n);
  vector<vector<int>> books(n, vector<int>(m));
  rep(i, n) {
    cin >> b_val[i];
    rep(j, m) { cin >> books[i][j]; }
  }

  // bit 全探索
  ll res = 1e18;
  for (int bit = 0; bit < (1 << n); ++bit) {
    vector<ll> und(m, 0);
    ll money = 0;
    bool fg = true;
    // i番目に関する処理
    for (int i = 0; i < n; ++i) {
      if (bit & (1 << i)) {
        money += b_val[i];
        rep(j, m) und[j] += books[i][j];
      }
    }
    rep(i, m) {
      if (und[i] < k) {
        fg = false;
        break;
      }
    }
    if (fg)
      chmin(res, money);
  }
  if (res == 1e18)
    res = -1;
  cout << res << ln;
}

Error: WA

Fixed submission:

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln = '\\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  int n;
  ll k;
  cin >> n >> k;
  vector<int> A(n + 10);
  A.push_back(-1);
  rep(i, n) cin >> A[i + 1];

  ll ans = -1;
  vector<int> visited(200200, -1);
  visited[1] = 0;
  vector<int> pass;
  pass.push_back(1);

  int rp = -1, nrp, cur = 1;
  for (int i = 1; i <= n; i++) {
    int next = A[cur];
    if (visited[next] == -1) {
      pass.push_back(next);
      visited[next] = i;
      cur = next;
    } else {
      rp = i - visited[next];
      nrp = pass.size() - rp;
      break;
    }
  }
  ll x = (k - nrp) % rp;
  cout << pass[nrp + x] << ln;
}
Problem p02683 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
#define mp make_pair
#define INF 1e9

void init() {
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
}

int main(void) {
  init();
  int n, m, x;
  cin >> n >> m >> x;
  vector<pair<int, vector<int>>> data;
  rep(i, n) {
    int c;
    cin >> c;
    vector<int> a(m);
    rep(j, m) { cin >> a[j]; }
    data.push_back(mp(c, a));
  }

  int ans = INF;
  rep(tmp, (1 << n)) {
    bitset<20> bit_d(tmp);
    int C = 0;
    vector<int> A(m);
    rep(i, n) {
      if (bit_d.test(i) == true) {
        C += data[i].first;
        rep(j, m) { A[j] += data[i].second[j]; }
      }
    }
    int flag = 1;
    rep(j, m) {
      if (A[j] < x)
        flag = 0;
    }
    if (flag == 1 && ans > C) {
      ans = C;
    }
  }
  if (ans != INF) {
    cout << ans << endl;
  } else {
    cout << "-1" << endl;
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<int> a(200001);
vector<string> s(200001);
int n, ans = -1;

int main(void) {
  int N, M, X;
  cin >> N >> M >> X;
  vector<vector<int>> d(N, vector<int>(M + 1));
  vector<int> label(N);
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M + 1; j++) {
      cin >> d[i][j];
    }
    label[i] = i;
  }
  int flag;
  do {
    vector<int> sum(M + 1, 0);
    for (int i = 0; i < N; i++) {
      flag = 1;
      for (int j = 0; j < M + 1; j++) {
        sum[j] += d[label[i]][j];
        if (X > sum[j] && j >= 1)
          flag = 0;
      }
      if (flag == 1) {
        if (ans == -1) {
          ans = sum[0];
        }
        if (ans > sum[0]) {
          ans = sum[0];
        }
        break;
      }
      if (sum[0] > ans && ans != -1)
        break;
    }
  } while ((next_permutation(label.begin(), label.end())));
  cout << ans << endl;
}
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int n, m, x;
int c[22];
int a[22][22];
int ptr;
string s[4444];
int q[22];
void dfs(string cnt) {
  if (cnt.size() == n) {
    s[ptr++] = cnt;
    return;
  }
  dfs(cnt + '1');
  dfs(cnt + '0');
}
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];
  }
  dfs("0");
  dfs("1");
  int ans = 1e9;
  for (int i = 0; i < ptr; i++) {
    int cur = 0;
    for (int j = 0; j < m; j++)
      q[j] = 0;
    for (int j = 0; j < s[i].size(); j++)
      if (s[i][j] == '1') {
        cur += c[j];
        for (int k = 0; k < m; k++)
          q[k] += a[j][k];
      }
    bool flag = true;
    for (int j = 0; j < m; j++)
      if (q[j] < x)
        flag = false;
    if (flag == true)
      ans = min(ans, cur);
  }
  if (ans == 1e9)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int n, m;
string s[22];
pair<string, string> e[22];
int ptr;
string cnt[22];
vector<string> ans;
void dfs(string i) {
  if (i.size() == n) {
    cnt[ptr++] = i;
    return;
  }
  dfs(i + "0");
  dfs(i + "1");
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    cin >> s[i];
  dfs("0");
  dfs("1");
  for (int i = 0; i < m; i++) {
    string a, b;
    cin >> a >> b;
    e[i].first = a;
    e[i].second = b;
  }
  int best = 0;
  for (int i = 0; i < ptr; i++) {
    vector<string> q;
    for (int j = 0; j < cnt[i].size(); j++)
      if (cnt[i][j] == '1')
        q.push_back(s[j]);
    bool flag = true;
    for (int i = 0; i + 1 < q.size(); i++)
      for (int j = i + 1; j < q.size(); j++)
        for (int k = 0; k < m; k++)
          if (e[k].first == q[i] && e[k].second == q[j])
            flag = false;
    if (q.size() > best && flag == true) {
      best = q.size();
      ans = q;
    }
  }
  cout << best << endl;
  for (int i = 0; i < ans.size(); i++)
    cout << ans[i] << endl;
  return 0;
}
Problem p02683 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

void solve() {
  int n, m, xx;
  cin >> n >> m >> xx;
  vector<vector<int>> a(n, vector<int>(m));
  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];
  }
  ll ans = INT_MAX;
  for (int i = 0; i < 1 << (n); i++) {
    string s = "";
    int x = i;
    while (x > 0) {
      s += char(x % 2 + '0');
      x /= 2;
    }
    int t = s.size();
    for (int j = 0; j < n - t; j++)
      s += '0';

    ll cost = 0;
    map<int, int> b;
    for (int j = 0; j < n; j++) {
      if (s[j] == '1') {
        cost += c[j];
        for (int k = 0; k < m; k++) {
          b[k] += a[j][k];
        }
      }
      bool ok = true;
      // cout << j << ' ' << "l\\n";
      for (int k = 0; k < m; k++) {
        // cout << b[k] << ' ';
        if (b[k] < xx) {
          ok = false;
          break;
        }
      }
      // cout << endl;

      if (ok) {
        // cout << cost << endl;
        ans = min(ans, cost);
        break;
      }
    }
  }
  cout << (ans == INT_MAX ? -1 : ans);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--)
    solve();
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

void solve() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<vector<int>> a(n, vector<int>(m));
  vector<int> p(n), c(n);
  for (int i = 0; i < n; i++) {
    p[i] = i;
    cin >> c[i];
    for (int j = 0; j < m; j++)
      cin >> a[i][j];
  }
  ll ans = INT_MAX;
  map<int, int> b;
  do {
    ll cost = 0;
    for (int i = 0; i < n; i++) {
      cost += c[p[i]];
      for (int j = 0; j < m; j++) {
        b[j] += a[p[i]][j];
      }
      bool ok = true;
      for (int j = 0; j < m; j++) {
        if (b[j] < x) {
          ok = false;
          break;
        }
      }
      if (ok) {
        ans = min(ans, cost);
        break;
      }
    }
    b.clear();
  } while (next_permutation(p.begin(), p.end()));
  if (ans == INT_MAX)
    cout << -1;
  else
    cout << ans;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--)
    solve();
}
Problem p02683 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
const int MAXN = 20;
int n, m, x;
int c[MAXN];
int a[MAXN][MAXN];
int t[MAXN], ans = 0x3f3f3f3f;
inline int read() {
  int tot = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    tot = (tot << 1) + (tot << 3) + (c ^ 48);
    c = getchar();
  }
  return tot * f;
}
inline bool check() {
  for (int i = 1; i <= m; i++)
    if (t[i] < x)
      return 0;
  return 1;
}
inline void dfs(int now, int val) {
  if (val >= ans)
    return;
  if (now > n) {
    if (check())
      ans = min(ans, val);
    return;
  }
  dfs(now + 1, val);
  for (int j = 1; j <= m; j++) {
    t[j] += a[now][j];
  }
  dfs(now + 1, val + c[now]);
  for (int j = 1; j <= m; j++) {
    t[j] -= a[now][j];
  }
}
signed main() {
  n = read();
  m = read();
  x = read();
  for (int i = 1; i <= n; i++) {
    c[i] = read();
    for (int j = 1; j <= m; j++) {
      a[i][j] = read();
      t[j] += a[i][j];
    }
  }
  if (!check()) {
    cout << -1 << endl;
    return 0;
  }
  memset(t, 0, sizeof(t));
  dfs(1, 0);
  printf("%d\\n", ans);
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int MAXN = 20;
int n, m, x;
int c[MAXN];
int a[MAXN][MAXN];
int t[MAXN], ans = 0x3f3f3f3f;
bool vis[MAXN];
inline int read() {
  int tot = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    tot = (tot << 1) + (tot << 3) + (c ^ 48);
    c = getchar();
  }
  return tot * f;
}
inline bool check() {
  for (int i = 1; i <= m; i++)
    if (t[i] < x)
      return 0;
  return 1;
}
inline void dfs(int val) {
  if (val >= ans)
    return;
  if (check()) {
    ans = min(ans, val);
  }
  for (int i = 1; i <= n; i++) {
    if (vis[i])
      continue;
    vis[i] = 1;
    for (int j = 1; j <= m; j++) {
      t[j] += a[i][j];
    }
    dfs(val + c[i]);
    vis[i] = 0;
    for (int j = 1; j <= m; j++) {
      t[j] -= a[i][j];
    }
  }
}
signed main() {
  n = read();
  m = read();
  x = read();
  for (int i = 1; i <= n; i++) {
    c[i] = read();
    for (int j = 1; j <= m; j++) {
      a[i][j] = read();
      t[j] += a[i][j];
    }
  }
  if (!check()) {
    cout << -1 << endl;
    return 0;
  }
  memset(t, 0, sizeof(t));
  dfs(0);
  printf("%d\\n", ans);
  return 0;
}
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
const int N = 109;
int n, m, x, c[N], a[N][N], p[N], ans = 0x3f3f3f3f;
void dfs(int s, int price) {
  if (s == n + 1) {
    for (int i = 1; i <= m; i++)
      if (p[i] < x)
        return;
    ans = min(ans, price);
    return;
  }
  dfs(s + 1, price);
  for (int i = 1; i <= m; i++)
    p[i] += a[s][i];
  dfs(s + 1, price + c[s]);
  for (int i = 1; i <= m; i++)
    p[i] -= a[s][i];
}
int main() {
  cin >> n >> m >> x;
  for (int i = 1; i <= n; i++) {
    cin >> c[i];
    for (int j = 1; j <= m; j++)
      cin >> a[i][j];
  }
  dfs(1, 0);
  if (ans > 1e9)
    cout << -1;
  else
    cout << ans;
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
struct node {
  int pri;
  int a[15];
} st[15];
int ans = 1e8;
int b[15];
int d[15];
int n, m, x;
int len;
int dfs(int p) {
  if (p == len + 1) {
    int sum = 0;
    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 <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <set>
#include <sstream>
#include <string>

typedef long long ll;

using namespace std;
const int INF = 0x3f3f3f3f;
const int MAXN = 15;
const int MOD = 10000;

struct BOOK {
  int price;
  int a[MAXN];
} book[MAXN];
int b[MAXN];

int main() {
  int n, m, x, price, level, ans = INF, res = 0;
  bool flag;
  scanf("%d %d %d", &n, &m, &x);

  for (int i = 0; i < n; i++) {
    scanf("%d", &book[i].price);
    for (int j = 0; j < m; j++) {
      scanf("%d", &book[i].a[j]);
    }
  }

  for (int i = 1; i < (1 << n); i++) {
    res = 0; // 统计每种情况所有书的总价格
    memset(b, 0, sizeof(b));
    for (int j = 0; j < n; j++) {
      if (i >> j & 1) {
        res += book[j].price;
        for (int k = 0; k < m; k++) {
          b[k] += book[j].a[k];
        }
      }
    }
    flag = true;
    for (int k = 0; k < m; k++) {
      if (b[k] < x) {
        flag = false;
        break;
      }
    }

    if (flag)
      ans = min(ans, res);
  }

  printf("%d", ans == INF ? -1 : ans);
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream> //C
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const ll maxn = 1e5 + 5;
int n, m, x;
int a[15][15];
struct node {
  int id;
  int mon;
  bool operator<(node &other) const { return mon > other.mon; }
} c[15];
ll sum[15], cnt = 0;
ll slove() {
  int flag = 0;
  for (int i = 1; i <= n; i++) {
    int b = c[i].id;
    // cout<<"mon: "<<c[i].mon<<endl;
    for (int j = 1; j <= m; j++) {
      // cout<<sum[j]<<" ";
      if (sum[j] < x) {
        flag = 2;
        break;
      } else if (sum[j] - a[b][j] >= x) {
        sum[j] = sum[j] - a[b][j];
        flag = 1;
      } else {
        flag = 0;
        break;
      }
    }
    // cout<<"cnt: "<<cnt<<endl;
    if (flag == 1)
      cnt -= c[i].mon;
    if (flag == 2) {
      printf("-1\\n");
      break;
    }
  }
  if (flag != 2)
    cout << cnt << endl;
}
int main() {
  cin >> n >> m >> x;
  for (int i = 1; i <= n; i++) {
    cin >> c[i].mon;
    c[i].id = i;
    cnt += c[i].mon;
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
      sum[j] += a[i][j];
    }
  }
  sort(c + 1, c + n + 1);
  slove();
  return 0;
}
Problem p02683 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <stdlib.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) {
  if (pos == n + 1) {
    for (int i = 1; i <= m; i++)
      if (ans[i] < x)
        return;
    price = min(price, sum);
    return;
  }
  dfs(pos + 1);
  for (int j = 1; j <= m; j++)
    ans[j] += a[pos][j];
  sum += mon[pos];
  dfs(pos + 1);
  for (int i = 1; i <= m; i++)
    ans[i] -= a[pos][i];
  sum -= mon[pos];
}
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);
  if (price == 1e9)
    cout << -1 << '\\n';
  else
    cout << price << '\\n';
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
struct node {
  int pri;
  int a[15];
} st[15];
int arr[1000];
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>
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
typedef long long ll;
using namespace std;

bool check(vector<int> und, int x) {
  rep(i, und.size()) {
    if (und[i] < x)
      return false;
  }
  return true;
}

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

  vector<vector<int>> a;
  vector<int> c;
  a.resize(n);
  c.resize(n);
  rep(i, n) {
    cin >> c[i];
    a[i].resize(m);
    rep(j, m) cin >> a[i][j];
  }

  int ans = 1 << 30;
  rep(i, (1 << n)) {
    vector<int> und(m, 0);
    int cost = 0;
    rep(j, n) {
      if (i & (1 << j)) {
        cost += c[j];
        rep(k, m) und[k] += a[j][k];
      }
    }
    if (check(und, x))
      ans = cost < ans ? cost : ans;
  }

  if (ans == 1 << 30)
    ans = -1;
  cout << ans << endl;
}

Error: 0

Fixed submission:

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

int n, m, x;
vector<int> c;
vector<vector<int>> a;

bool check(vector<int> sum) {
  rep(i, m) {
    if (sum[i] < x)
      return false;
  }
  return true;
}

int ref(int cnt, vector<int> sum, ll sum_c) {
  if (check(sum))
    return sum_c;
  if (cnt >= n)
    return INF;

  vector<int> ori(n, 0); // 元の値を保存
  rep(i, n) ori[i] = sum[i];

  ll ref1 = ref(cnt + 1, sum, sum_c); // 足さないやつ
  rep(i, n) sum[i] = ori[i];          // もとの値に戻す

  rep(i, m) sum[i] += a[cnt][i];
  ll ref2 = ref(cnt + 1, sum, sum_c + c[cnt]); // 足すやつ

  return min(ref1, ref2);
}

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

  vector<int> sum_a(m, 0);

  ll ans = ref(0, sum_a, 0);
  ans = (ans >= INF) ? -1 : ans;

  cout << ans << endl;
}