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

/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Ankur Dua
 */

#include <fstream>
#include <iostream>

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
ll mod = 1000000007;
ll *fact, *ifact;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll modExp(ll base, ll exp, ll mod = ::mod) {
  ll ans = 1;
  while (exp) {
    if (exp & 1) {
      (ans *= base) %= mod;
    }
    (base *= base) %= mod;
    exp >>= 1;
  }
  return ans;
}
ll modInv(ll x, ll mod = ::mod) { return modExp(x, mod - 2, mod); }
void modFact(ll n, ll mod = ::mod) {
  ifact = new ll[n + 1];
  fact = new ll[n + 1];
  fact[0] = fact[1] = 1;
  for (int i = 2; i <= n; i++) {
    fact[i] = (i * fact[i - 1]) % mod;
  }
  ifact[n] = modInv(fact[n], mod);
  for (int i = n - 1; i >= 0; i--) {
    ifact[i] = ((i + 1) * ifact[i + 1]) % mod;
  }
}
ll ncr(ll n, ll r, ll mod = ::mod) {
  if (n < r || r < 0)
    return 0;
  ll ans = fact[n];
  ans *= ifact[r];
  ans %= mod;
  ans *= ifact[n - r];
  ans %= mod;
  return ans;
}
ll npr(ll n, ll r, ll mod = ::mod) {
  if (n < r || r < 0)
    return 0;
  ll ans = fact[n];
  ans *= ifact[n - r];
  return ans % mod;
}

template <typename T> void coordinateCompress(vector<T> &v, T start = 1) {
  vector<T> cpy = v;
  sort(cpy.begin(), cpy.end());
  map<T, T> mp;
  for (T x : cpy) {
    mp[x] = start++;
  }
  for (T &x : v) {
    x = mp[x];
  }
}
template <typename T1, typename T2>
istream &operator>>(istream &cin, pair<T1, T2> &p) {
  cin >> p.first >> p.second;
  return cin;
}
using namespace std;

class CSkillUp {
public:
  void solve(std::istream &cin, std::ostream &cout) {
    int x, sol = INT_MAX;
    function<void(vector<vector<int>> & v, int n, int m, vector<int> &ans,
                  int amt)>
        solve = [&](vector<vector<int>> &v, int n, int m, vector<int> &ans,
                    int amt) {
          if (n == 0) {
            for (int i = 0; i < m; i++)
              if (ans[i] < x)
                return;
            sol = min(sol, amt);
            return;
          }
          solve(v, n - 1, m, ans, amt);
          for (int i = 1; i <= m; i++)
            ans[i - 1] += v[n - 1][i];
          amt += v[n - 1][0];
          solve(v, n - 1, m, ans, amt);
          for (int i = 1; i <= m; i++)
            ans[i - 1] -= v[n - 1][i];
        };
    int n, m, amt = 0;
    cin >> n >> m >> x;
    vector<int> v1, ans(m, 0);
    vector<vector<int>> v(n, v1);
    for (int i = 0; i < n; i++)
      for (int j = 0; j <= m; j++) {
        int val;
        cin >> val;
        v[i].push_back(val);
      }
    solve(v, n, m, ans, amt);
    if (sol == INT_MAX)
      cout << -1;
    else
      cout << sol;
  }
};

int main() {
  CSkillUp solver;
  std::ios::sync_with_stdio(false);
  std::cin.tie(NULL);
  std::cout.tie(NULL);
  std::istream &in(std::cin);
  std::ostream &out(std::cout);
  solver.solve(in, out);
  return 0;
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int x, sol = INT_MAX;
void solve(vector<vector<int>> &v, int n, int m, vector<int> &ans, int amt) {
  if (n == 0) {
    for (int i = 0; i < m; i++)
      if (ans[i] < x)
        return;
    sol = min(sol, amt);
  }
  solve(v, n - 1, m, ans, amt);
  for (int i = 1; i <= m; i++)
    ans[i - 1] += v[n - 1][i];
  amt += v[n - 1][0];
  solve(v, n - 1, m, ans, amt);
  for (int i = 1; i <= m; i++)
    ans[i - 1] -= v[n - 1][i];
}
int main() {
  int n, m, amt = 0;
  cin >> n >> m >> x;
  vector<int> v1, ans(m, 0);
  vector<vector<int>> v(n, v1);
  for (int i = 0; i < n; i++)
    for (int j = 0; j <= m; j++) {
      int val;
      cin >> val;
      v[i].push_back(val);
    }
  //	for (int i=0;i<n;i++){
  //		for (int j=0;j<m+1;j++)
  //			cout<<v[i][j]<<" ";
  //		cout<<endl;
  //	}
  //	for (int i=0;i<m;i++)
  //		cout<<ans[i]<<" ";
  //	cout<<sol<<" "<<amt;
  solve(v, n, m, ans, amt);
  if (sol == INT_MAX)
    cout << -1;
  else
    cout << sol;
}