Problem p03503 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <climits>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define rep(i, m, n) for (int i = int(m); i < int(n); i++)
#define EACH(i, c) for (auto &(i) : c)
#define all(c) begin(c), end(c)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(begin(c), end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

// #define LOCAL 0
// #ifdef LOCAL
// #define DEBUG(s) cout << (s) << endl
// #define dump(x)  cerr << #x << " = " << (x) << endl
// #define BR cout << endl;
// #else
// #define DEBUG(s) do{}while(0)
// #define dump(x) do{}while(0)
// #define BR
// #endif

// 改造
typedef long long int ll;
using namespace std;
#define INF (1 << 20)
#define INFl (ll)5e15
#define DEBUG 0 // デバッグする時1にしてね

// ここから編集する

int main() {
  int N;
  cin >> N;
  vector<vector<int>> v(N, vector<int>(10)), P(N, vector<int>(11));
  rep(i, 0, N) {
    rep(j, 0, 10) { cin >> v[i][j]; }
  }

  rep(i, 0, N) {
    rep(j, 0, 11) { cin >> P[i][j]; }
  }

  ll ans = -(ll)(1e9);
  for (int i = 1; i < (1 << 10); i++) {
    // jの店と何個被ってるか
    vector<int> kabu(10);
    for (int j = 0; j < N; j++) {
      int cnt = 0;
      for (int k = 0; k < 10; k++) {
        if (v[j][k] == 1 && ((i >> k) & 1) == 1) {
          cnt++;
        }
      }
      kabu[j] = cnt;
    }

    ll ans_tmp = 0;
    for (int j = 0; j < N; j++) {
      ans_tmp += 1LL * P[j][kabu[j]];
    }
    ans = max(ans, ans_tmp);
    //        if(ans == 0){
    //            cout << "0" << endl;
    //        }
  }

  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <climits>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define rep(i, m, n) for (int i = int(m); i < int(n); i++)
#define EACH(i, c) for (auto &(i) : c)
#define all(c) begin(c), end(c)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(begin(c), end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

// #define LOCAL 0
// #ifdef LOCAL
// #define DEBUG(s) cout << (s) << endl
// #define dump(x)  cerr << #x << " = " << (x) << endl
// #define BR cout << endl;
// #else
// #define DEBUG(s) do{}while(0)
// #define dump(x) do{}while(0)
// #define BR
// #endif

// 改造
typedef long long int ll;
using namespace std;
#define INF (1 << 20)
#define INFl (ll)5e15
#define DEBUG 0 // デバッグする時1にしてね

// ここから編集する

int main() {
  int N;
  cin >> N;
  vector<vector<int>> v(N, vector<int>(10)), P(N, vector<int>(11));
  rep(i, 0, N) {
    rep(j, 0, 10) { cin >> v[i][j]; }
  }

  rep(i, 0, N) {
    rep(j, 0, 11) { cin >> P[i][j]; }
  }

  ll ans = -(ll)(1e9);
  for (int i = 1; i < (1 << 10); i++) {
    // jの店と何個被ってるか
    vector<int> kabu(N);
    for (int j = 0; j < N; j++) {
      int cnt = 0;
      for (int k = 0; k < 10; k++) {
        if (v[j][k] == 1 && ((i >> k) & 1) == 1) {
          cnt++;
        }
      }
      kabu[j] = cnt;
    }

    ll ans_tmp = 0;
    for (int j = 0; j < N; j++) {
      ans_tmp += 1LL * P[j][kabu[j]];
    }
    ans = max(ans, ans_tmp);
    //        if(ans == 0){
    //            cout << "0" << endl;
    //        }
  }

  cout << ans << endl;

  return 0;
}