Problem p02618 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

long long D = 365, type = 26, inf = 1001001001;
vector<long long> C(type);
vector<vector<long long>> S(D, vector<long long>(type));

struct STR {
  long long score;
  vector<long long> ans;
  vector<long long> last;
};
bool operator<(const STR &left, const STR &right) {
  if (left.score < right.score)
    return true;
  else
    return false;
}

void input() {
  cin >> D;
  for (int i = 0; i < type; i++)
    cin >> C[i];
  for (int i = 0; i < D; i++) {
    for (int j = 0; j < type; j++) {
      cin >> S[i][j];
    }
  }
  return;
}

long long calc(long long day, long long t, vector<long long> &last) {
  long long score = S[day][t];
  for (int i = 0; i < type; i++) {
    score -= C[i] * (day - last[i]);
  }
  return score;
}

int main() {
  input();

  long long score = 0;
  vector<long long> last(type, -1), V(0);
  vector<priority_queue<STR>> Q(2);
  STR s = {score, V, last};
  Q[0].push(s);
  for (int i = 0; i < D; i++) {
    while (!Q[(i + 1) % 2].empty())
      Q[(i + 1) % 2].pop();
    for (int j = 0; j < 50; j++) {
      if (Q[i % 2].empty())
        break;
      STR str = Q[i % 2].top();
      Q[i % 2].pop();

      for (int k = 0; k < type; k++) {
        long long x = calc(i, k, str.last);
        vector<long long> y = str.last, z = str.ans;
        y[k] = i;
        z.push_back(k);
        STR str2 = {x, z, y};
        Q[(i + 1) % 2].push(str2);
      }
    }
  }

  vector<long long> ans = Q[D].top().ans;
  for (int i = 0; i < D; i++)
    cout << ans[i] + 1 << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

long long D = 365, type = 26, inf = 1001001001;
vector<long long> C(type);
vector<vector<long long>> S(D, vector<long long>(type));

struct STR {
  long long score;
  vector<long long> ans;
  vector<long long> last;
};
bool operator<(const STR &left, const STR &right) {
  if (left.score < right.score)
    return true;
  else
    return false;
}

void input() {
  cin >> D;
  for (int i = 0; i < type; i++)
    cin >> C[i];
  for (int i = 0; i < D; i++) {
    for (int j = 0; j < type; j++) {
      cin >> S[i][j];
    }
  }
  return;
}

long long calc(long long day, long long t, vector<long long> &last) {
  long long score = S[day][t];
  for (int i = 0; i < type; i++) {
    score -= C[i] * (day - last[i]);
  }
  return score;
}

int main() {
  input();

  long long score = 0;
  vector<long long> last(type, -1), V(0);
  vector<priority_queue<STR>> Q(2);
  STR s = {score, V, last};
  Q[0].push(s);
  for (int i = 0; i < D; i++) {
    while (!Q[(i + 1) % 2].empty())
      Q[(i + 1) % 2].pop();
    for (int j = 0; j < 50; j++) {
      if (Q[i % 2].empty())
        break;
      STR str = Q[i % 2].top();
      Q[i % 2].pop();

      for (int k = 0; k < type; k++) {
        long long x = calc(i, k, str.last);
        vector<long long> y = str.last, z = str.ans;
        y[k] = i;
        z.push_back(k);
        STR str2 = {x, z, y};
        Q[(i + 1) % 2].push(str2);
      }
    }
  }

  vector<long long> ans = Q[D % 2].top().ans;
  for (int i = 0; i < D; i++)
    cout << ans[i] + 1 << endl;
  return 0;
}