Problem p03503 (C++)

Buggy submission (status: Runtime Error):
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int> &f, const pair<int, int> &s) {
  return f.second > s.second;
}

int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

ll nCm(ll n, ll m) {
  if (m == 0 || m == n)
    return (1);
  else if (m == 1)
    return (n);
  return (nCm(n - 1, m) + nCm(n - 1, m - 1));
}

//-----------------------ここから-----------

int main(void) {
  int n;
  cin >> n;

  int f[110][15] = {0};

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> f[i][j];
    }
  }

  vector<vector<int>> p(n, vector<int>(10));

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 11; j++) {
      cin >> p[i][j];
    }
  }

  int ans = -1e9;
  for (int bit = 1; bit < (1 << 10); bit++) {
    vector<int> l;
    bool empty = true;
    for (int i = 0; i < 10; i++) {
      if (bit & (1 << i)) {
        l.push_back(i);
        empty = false;
      }
    }
    if (empty)
      continue;

    int totalprofit = 0;
    for (int i = 0; i < n; i++) {
      int totalopen = 0;
      for (int j = 0; j < l.size(); j++) {
        if (f[i][l[j]] == 1) {
          totalopen++;
        }
      }
      totalprofit += p[i][totalopen];
    }

    if (totalprofit > ans) {
      ans = totalprofit;
    }
  }
  cout << ans << endl;
}

Fixed submission:
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int> &f, const pair<int, int> &s) {
  return f.second > s.second;
}

int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

ll nCm(ll n, ll m) {
  if (m == 0 || m == n)
    return (1);
  else if (m == 1)
    return (n);
  return (nCm(n - 1, m) + nCm(n - 1, m - 1));
}

//-----------------------ここから-----------

int main(void) {
  int n;
  cin >> n;

  int f[110][15] = {0};

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> f[i][j];
    }
  }

  vector<vector<int>> p(n, vector<int>(11));

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 11; j++) {
      cin >> p[i][j];
    }
  }

  int ans = -1e9;
  for (int bit = 1; bit < (1 << 10); bit++) {
    vector<int> l;
    bool empty = true;
    for (int i = 0; i < 10; i++) {
      if (bit & (1 << i)) {
        l.push_back(i);
        empty = false;
      }
    }
    if (empty)
      continue;

    int totalprofit = 0;
    for (int i = 0; i < n; i++) {
      int totalopen = 0;
      for (int j = 0; j < l.size(); j++) {
        if (f[i][l[j]] == 1) {
          totalopen++;
        }
      }
      totalprofit += p[i][totalopen];
    }

    if (totalprofit > ans) {
      ans = totalprofit;
    }
  }
  cout << ans << endl;
}