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

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double EPS = 1e-9;
const double INT_MAX = 2147483647;
#define rep(i, n) REP(i, 0, n)
#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rrep(i, n) RREP(i, 0, n)
#define RREP(i, x, n) for (int i = (int)(n)-1 - (int)(x); i >= 0; i--)

void printv(vector<int> v) {
  for (auto it = v.begin(); it != v.end(); it++) {
    cout << *it << ",";
  }
  cout << endl;
}

int N, M, X;
vector<int> c(13);
vector<vector<int>> a(13, vector<int>(13));
int res = INT_MAX;

void rec(vector<int> s, int d, int sum) {
  // cout<<"d:"<<d<<" sum:"<<sum<<endl;
  // printv(s);
  if (d == N + 1)
    return;
  bool r = true;
  rep(i, M) {
    if (s[i] < X)
      r = false;
  }
  if (r && res > sum)
    res = sum;
  // dばんめを選ばない場合
  rec(s, d + 1, sum);
  // 選ぶ場合
  if (r)
    return;
  rep(i, M) { s[i] += a[d][i]; }
  rec(s, d + 1, sum + c[d]);
}

int main(void) {
  // Your code here!
  cin >> N >> M >> X;
  rep(i, N) {
    cin >> c[i];
    rep(j, M) { cin >> a[i][j]; }
  }
  vector<int> s(M);
  rec(s, 0, 0);
  if (res == INT_MAX)
    cout << "-1";
  else
    cout << res;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double EPS = 1e-9;
const double INT_MAX = 2147483647;
#define rep(i, n) REP(i, 0, n)
#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rrep(i, n) RREP(i, 0, n)
#define RREP(i, x, n) for (int i = (int)(n)-1 - (int)(x); i >= 0; i--)

void printv(vector<int> v) {
  for (auto it = v.begin(); it != v.end(); it++) {
    cout << *it << ",";
  }
  cout << endl;
}

int N, M, X;
vector<int> c(13);
vector<vector<int>> a(13, vector<int>(13));
int res = INT_MAX;

void rec(vector<int> s, int d, int sum) {
  // cout<<"d:"<<d<<" sum:"<<sum<<endl;
  // printv(s);
  if (d == N + 1)
    return;
  bool r = true;
  rep(i, M) {
    if (s[i] < X)
      r = false;
  }
  if (r && res > sum)
    res = sum;
  // dばんめを選ばない場合
  rec(s, d + 1, sum);
  // 選ぶ場合
  if (r)
    return;
  rep(i, M) { s[i] += a[d][i]; }
  rec(s, d + 1, sum + c[d]);
}

int main(void) {
  // Your code here!
  cin >> N >> M >> X;
  rep(i, N) {
    cin >> c[i];
    rep(j, M) { cin >> a[i][j]; }
  }
  vector<int> s(N);
  rec(s, 0, 0);
  if (res == INT_MAX)
    cout << "-1";
  else
    cout << res;
}