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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<double> VL;
typedef vector<string> VS;
typedef vector<PLL> VP;
typedef vector<ll> VLL;
const static int INF = 1000000000;
const static int MOD = 1000000007;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repd(i, n) for (ll i = n - 1; i >= 0; i--)
#define rept(i, m, n) for (ll i = m; i < n; i++)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V)                                                               \\
  for (auto v : (V))                                                           \\
  cout << v << " "
// charを整数に
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
// 累積和 for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i];
void cum_sum(int N, vector<double> a, vector<double> &s) {
  for (int i = 0; i < N; i++) {
    s[i + 1] = s[i] + a[i];
  }
}
// ユークリッドの控除法
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
// 最小公倍数
ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a / g * b; // Be careful not to overflow
}
// 空白文字も入力 getline(cin, S);
// 桁数指定 setprecision

int main() {
  int N, M, X;
  cin >> N >> M >> X;
  VI C(N);
  vector<vector<int>> A(N, vector<int>(M));
  rep(i, N) {
    cin >> C[i];
    rep(j, M) { cin >> A[i][j]; }
  }
  bool end = true;
  int money = 1000000000;
  VI judge(M);
  for (int i = 0; i < (1 << N); i++) {
    int max = 0;
    rep(j, N) {
      if ((i >> j) & 1) {
        rep(k, M) { judge[k] += A[j][k]; }
        max += C[j];
      }
    }
    rep(i, M) {
      if (judge[i] < X) {
        end = false;
      }
    }
    if (end) {
      if (money > max) {
        money = max;
      }
    }
    end = true;
    rep(i, M) { judge[i] = 0; }
  }
  if (money == INF) {
    cout << -1 << endl;
  } else {
    cout << money << endl;
  }
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<double> VL;
typedef vector<string> VS;
typedef vector<PLL> VP;
typedef vector<ll> VLL;
const static int INF = 1000000000;
const static int MOD = 1000000007;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repd(i, n) for (ll i = n - 1; i >= 0; i--)
#define rept(i, m, n) for (ll i = m; i < n; i++)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V)                                                               \\
  for (auto v : (V))                                                           \\
  cout << v << " "
// charを整数に
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
// 累積和 for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i];
void cum_sum(int N, vector<double> a, vector<double> &s) {
  for (int i = 0; i < N; i++) {
    s[i + 1] = s[i] + a[i];
  }
}
// ユークリッドの控除法
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
// 最小公倍数
ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a / g * b; // Be careful not to overflow
}
// 空白文字も入力 getline(cin, S);
// 桁数指定 setprecision

int main() {
  ll N, M, X;
  cin >> N >> M >> X;
  VLL C(N);
  vector<vector<ll>> A(N, vector<ll>(M));
  rep(i, N) {
    cin >> C[i];
    rep(j, M) { cin >> A[i][j]; }
  }
  VLL all_score(M);
  rep(i, N) {
    rep(j, M) { all_score[i] += A[i][j]; }
  }
  rep(i, N) {
    if (all_score[i] < X) {
      cout << -1 << endl;
      return 0;
    }
  }
  vector<pair<long double, long double>> ave(N);
  VLL memory(N);
  rep(i, N) {
    long double sum = 0;
    rep(j, M) { sum += A[i][j]; }
    ave.at(i).F = sum / M;
    ave.at(i).F = ave.at(i).F / C[i];
    ave.at(i).S = i;
  }
  bool end = true;
  ll money = 0;
  sort(all(ave));
  reverse(all(ave));
  VLL judge(M);
  rep(i, N) {
    rep(j, M) { judge[j] += A[ave[i].S][j]; }
    money += C[ave[i].S];
    rep(j, M) {
      if (judge[j] < X) {
        end = false;
      }
    }
    if (end) {
      cout << money << endl;
      return 0;
    }
    end = true;
  }
  cout << -1 << endl;
}