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

#include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pl(s) cout << (s) << "\\n";
#define pls(...)                                                               \\
  {                                                                            \\
    bool space = false;                                                        \\
    for (auto i : __VA_ARGS__)                                                 \\
      (cout << (space ? " " : "") << i), space = true;                         \\
    cout << "\\n";                                                              \\
  }
#define plexit(s)                                                              \\
  {                                                                            \\
    cout << (s) << "\\n";                                                       \\
    exit(0);                                                                   \\
  }
#define yes(s) cout << ((s) ? "Yes" : "No") << "\\n";
#ifdef __LOCAL
#include <dump.hpp>
#define dump(...)                                                              \\
  DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                              \\
          << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl  \\
          << "    ",                                                           \\
      dump_func(__VA_ARGS__)
#else
#define dump(...)
#endif
template <typename T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
struct IOInit {
  IOInit() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    dump("READY"); /*cout << unitbuf;*/
  }
} IO_INIT;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T = int> using V = vector<T>;
template <typename T = int> using P = pair<T, T>;
using Vi = V<int>;
using Vl = V<ll>;
using Vd = V<ld>;
using VVi = V<Vi>;
using VVl = V<Vl>;
using Pi = P<int>;
using Pl = P<ll>;
using Pd = P<ld>;
constexpr ll MOD = 1000000007;
constexpr int INF = (1 << 30) - 1;
constexpr ll INFL = 1LL << 60;
constexpr ld EPS = 1e-12;
constexpr ld PI = 3.141592653589793238462643383279;

signed main(void) {
  int d;
  cin >> d;
  const int N = 26;
  Vi c(N);
  rep(i, N) cin >> c[i];
  VVi s(d, Vi(N));
  rep(i, d) rep(j, N) cin >> s[i][j];
  Vi last(N);

  auto getScore = [](int d, Vi &c, VVi &s, Vi &t) -> int {
    Vi last(N);
    int ret = 0;
    reps(i, d) {
      ret += s[i - 1][t[i - 1]];
      last[t[i - 1]] = i;
      rep(j, N) ret -= c[j] * (i - last[j]);
      // pl(ret)
    }
    return ret;
  };

  Vi t(d);
  reps(i, d) {
    int ma = -INF;
    t[i - 1] = 0;
    rep(j, N) {
      int ret = s[i - 1][j];
      last[j] = i;
      rep(k, N) ret -= c[j] * (i - last[j]);
      if (chmax(ma, ret)) {
        t[i - 1] = j;
      }
    }
  }

  // dump(getScore(d, c, s, t));

  rep(i, d) { pl(t[i] + 1) }

  // int m; cin >> m;
  // rep(i,m) {
  //   int d, q; cin >> d >> q;
  //   --d; --q;
  //   t[d] = q;
  //   pl(getScore())
  // }
  return 0;
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pl(s) cout << (s) << "\\n";
#define pls(...)                                                               \\
  {                                                                            \\
    bool space = false;                                                        \\
    for (auto i : __VA_ARGS__)                                                 \\
      (cout << (space ? " " : "") << i), space = true;                         \\
    cout << "\\n";                                                              \\
  }
#define plexit(s)                                                              \\
  {                                                                            \\
    cout << (s) << "\\n";                                                       \\
    exit(0);                                                                   \\
  }
#define yes(s) cout << ((s) ? "Yes" : "No") << "\\n";
#ifdef __LOCAL
#include <dump.hpp>
#define dump(...)                                                              \\
  DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                              \\
          << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl  \\
          << "    ",                                                           \\
      dump_func(__VA_ARGS__)
#else
#define dump(...)
#endif
template <typename T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
struct IOInit {
  IOInit() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    dump("READY"); /*cout << unitbuf;*/
  }
} IO_INIT;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T = int> using V = vector<T>;
template <typename T = int> using P = pair<T, T>;
using Vi = V<int>;
using Vl = V<ll>;
using Vd = V<ld>;
using VVi = V<Vi>;
using VVl = V<Vl>;
using Pi = P<int>;
using Pl = P<ll>;
using Pd = P<ld>;
constexpr ll MOD = 1000000007;
constexpr int INF = (1 << 30) - 1;
constexpr ll INFL = 1LL << 60;
constexpr ld EPS = 1e-12;
constexpr ld PI = 3.141592653589793238462643383279;

signed main(void) {
  int d;
  cin >> d;
  const int N = 26;
  Vi c(N);
  rep(i, N) cin >> c[i];
  VVi s(d, Vi(N));
  rep(i, d) rep(j, N) cin >> s[i][j];
  int score = 0;
  Vi last(N);

  reps(i, d) {
    int t;
    cin >> t;
    --t;
    score += s[i - 1][t];
    last[t] = i;
    int minus = 0;
    rep(j, N) { minus += c[j] * (i - last[j]); }
    score -= minus;
    pl(score)
  }
  return 0;
}