Problem p02683 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define NREP() for (ll i = 0; i < n; i++)
#define MREP() for (ll j = 0; j < m; j++)
#define REP(i, x, y) for (ll i = x; i < y; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define MSGF(x, n) MSG(fixed << setprecision(n) << x)
#define END(x)                                                                 \\
  cout << x << endl;                                                           \\
  exit(0);
#define IPT(v, n)                                                              \\
  REP(i, 0, n) { cin >> v[i]; }
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<ull> vul;
typedef vector<vector<ull>> vvul;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;

const static ll MOD = 1e9 + 7;
const static ll INF = 1LL << 30;

ll a, b, c, d, k, l, m, n, h, w, q, x, y;
string s, t;

ull ans = 0;
ll sum = 0;
ll cnt = 0;
ll cur = 0;
ll tmp = 0;
ll mini = INF;
ll maxi = 0;

double ave = 0.0;

ll mod_pow(ll base, ll power) {
  if (power == 0)
    return 1;
  if (power == 1)
    return base % MOD;
  if (power % 2 == 0)
    return ((mod_pow(base % MOD, (power / 2)) % MOD) *
            (mod_pow(base, (power / 2)) % MOD)) %
           MOD;
  return (base % MOD * (mod_pow(base % MOD, power - 1) % MOD)) % MOD;
}

ll mod_fact(ll number) {
  ll ret = 1;
  ll count = 1;
  while (count <= number) {
    ret *= (count % MOD);
    ret %= MOD;
    count++;
  }
  return ret % MOD;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

ull calc(vl c, vvl a, vector<bool> pos) {
  ll tmp_sum = 0;
  vl as(m + 10, 0);
  NREP() {
    if (pos[i]) {
      tmp_sum += c[i];
      MREP() { as[j] += a[i][j]; }
    }
  }

  MREP() {
    if (as[j] < x) {
      return INF;
    }
  }
  return tmp_sum;
}

void search(vl c, vvl a, ll idx, vector<bool> pos) {
  if (idx >= n) {
    ull ret = calc(c, a, pos);
    if (ret != INF) {
      ans = min(ans, ret);
    }
    return;
  }
  pos[idx] = false;
  search(c, a, idx + 1, pos);
  pos[idx] = true;
  search(c, a, idx + 1, pos);
}

int main() {
  cin >> n >> m >> x;
  vl c(n + 10);
  vvl a(n + 10, vector<ll>(n + 10, 0));

  ans = ULLONG_MAX;
  NREP() {
    cin >> c[i];
    MREP() { cin >> a[i][j]; }
  }

  vl as(m, 0);
  REP(i, 0, n) {
    MREP() { as[j] += a[i][j]; }
  }
  MREP() {
    if (as[j] < x) {
      END(-1)
    }
  }

  vector<bool> pos(n + 10, false);
  search(c, a, 0, pos);
  MSG(ans)
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define NREP() for (ll i = 0; i < n; i++)
#define MREP() for (ll j = 0; j < m; j++)
#define REP(i, x, y) for (ll i = x; i < y; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define MSGF(x, n) MSG(fixed << setprecision(n) << x)
#define END(x)                                                                 \\
  cout << x << endl;                                                           \\
  exit(0);
#define IPT(v, n)                                                              \\
  REP(i, 0, n) { cin >> v[i]; }
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<ull> vul;
typedef vector<vector<ull>> vvul;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;

const static ll MOD = 1e9 + 7;
const static ll INF = 1LL << 30;

ll a, b, c, d, k, l, m, n, h, w, q, x, y;
string s, t;

ull ans = 0;
ll sum = 0;
ll cnt = 0;
ll cur = 0;
ll tmp = 0;
ll mini = INF;
ll maxi = 0;

double ave = 0.0;

ll mod_pow(ll base, ll power) {
  if (power == 0)
    return 1;
  if (power == 1)
    return base % MOD;
  if (power % 2 == 0)
    return ((mod_pow(base % MOD, (power / 2)) % MOD) *
            (mod_pow(base, (power / 2)) % MOD)) %
           MOD;
  return (base % MOD * (mod_pow(base % MOD, power - 1) % MOD)) % MOD;
}

ll mod_fact(ll number) {
  ll ret = 1;
  ll count = 1;
  while (count <= number) {
    ret *= (count % MOD);
    ret %= MOD;
    count++;
  }
  return ret % MOD;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

ull calc(vl c, vvl a, vector<bool> pos) {
  ull tmp_sum = 0;
  vl as(m, 0);
  REP(i, 0, n) {
    if (pos[i]) {
      tmp_sum += c[i];
      MREP() { as[j] += a[i][j]; }
    }
  }

  MREP() {
    if (as[j] < x) {
      return INF;
    }
  }
  return tmp_sum;
}

void search(vl c, vvl a, ll idx, vector<bool> pos) {
  if (idx >= n) {
    ull ret = calc(c, a, pos);
    if (ret != INF) {
      ans = min(ans, ret);
    }
    return;
  }
  pos[idx] = false;
  search(c, a, idx + 1, pos);
  pos[idx] = true;
  search(c, a, idx + 1, pos);
}

int main() {
  cin >> n >> m >> x;
  vl c(n);
  vvl a(n, vector<ll>(n, 0));

  ans = ULLONG_MAX;
  NREP() {
    cin >> c[i];
    MREP() { cin >> a[i][j]; }
  }

  vl as(m, 0);
  REP(i, 0, n) {
    MREP() { as[j] += a[i][j]; }
  }

  MREP() {
    if (as[j] < x) {
      END(-1)
    }
  }

  vector<bool> pos(n, false);
  search(c, a, 0, pos);
  MSG(ans)
}