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

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define N_TIMES(i, n) for (uint64_t i = 0; i < n; ++i)
#define N_TIMES_REV(i, n) for (int64_t i = n - 1; i >= 0; --i)

template <typename T>
using maximum_heap = std::priority_queue<T, std::vector<T>, std::less<T>>;
template <typename T>
using minimum_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template <typename T>
std::istream &operator>>(std::istream &is, std::vector<T> &v) {
  for (typename std::vector<T>::size_type i = 0; i < v.size(); ++i) {
    is >> v[i];
  }
  return is;
}

using namespace std;

const uint64_t M = 26;

// B問題を踏まえて貪欲法で解く。
// 各d日目で最もスコアが最大となるような選択を行う。
int64_t solution1(uint64_t D, const vector<int64_t> &c,
                  const vector<vector<int64_t>> &s) {
  int64_t S = 0;

  vector<int64_t> last(M, 0);
  N_TIMES(d, D) {
    int64_t max_T = -1e+16, max_t = -1;
    N_TIMES(t, M) {
      int64_t T = s[d][t];
      N_TIMES(m, M) {
        if (m == t) {
          continue;
        }
        T -= c[m] * ((d + 1) - last[m]);
      }

      if (max_T < T) {
        max_T = T;
        max_t = t;
      }
    }
    cout << (max_t + 1) << endl;
    last[max_t] = d + 1;
    S += max_T;
  }

  return S;
}

int main() {
  uint64_t D;
  cin >> D;

  vector<int64_t> c(M);
  cin >> c;

  vector<vector<int64_t>> s(D, vector<int64_t>(M));
  N_TIMES(d, D) { cin >> s[d]; }

  solution1(D, c, s);

  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define N_TIMES(i, n) for (uint64_t i = 0; i < n; ++i)
#define N_TIMES_REV(i, n) for (int64_t i = n - 1; i >= 0; --i)

template <typename T>
using maximum_heap = std::priority_queue<T, std::vector<T>, std::less<T>>;
template <typename T>
using minimum_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template <typename T>
std::istream &operator>>(std::istream &is, std::vector<T> &v) {
  for (typename std::vector<T>::size_type i = 0; i < v.size(); ++i) {
    is >> v[i];
  }
  return is;
}

using namespace std;

const uint64_t M = 26;

// B問題を踏まえて貪欲法で解く。
// 各d日目で最もスコアが最大となるような選択を行う。
int64_t solution1(uint64_t D, const vector<int64_t> &c,
                  const vector<vector<int64_t>> &s) {
  int64_t S = 0;

  vector<int64_t> last(M, 0);
  N_TIMES(d, D) {
    int64_t max_T = 0, max_t = -1;
    N_TIMES(t, M) {
      int64_t T = s[d][t - 1];
      N_TIMES(m, M) {
        if (m == t) {
          continue;
        }
        T -= c[m] * ((d + 1) - last[m]);
      }

      if (max_T < T) {
        max_T = T;
        max_t = t;
      }
    }
    cout << (max_t + 1) << endl;
    last[max_t] = d + 1;
    S += max_T;
  }

  return S;
}

int main() {
  uint64_t D;
  cin >> D;

  vector<int64_t> c(M);
  cin >> c;

  vector<vector<int64_t>> s(D, vector<int64_t>(M));
  N_TIMES(d, D) { cin >> s[d]; }

  solution1(D, c, s);

  return 0;
}