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

#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <cstdint> // int64_t, int*_t
#include <cstdio>  // printf
#include <cstdlib>
#include <deque> // deque
#include <iomanip>
#include <iostream>
#include <limits>
#include <map> // map
#include <numeric>
#include <queue> // queue, priority_queue
#include <set>   // set
#include <stack> // stack
#include <stdio.h>
#include <string>        // string, to_string, stoi
#include <tuple>         // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) { return max(max(a, b), c); }
ll Min(ll(a), ll(b), ll(c)) { return min(min(a, b), c); }

int main() {
  ll D;
  cin >> D;
  vector<ll> c(27);
  vector<vector<ll>> s(D + 1, vector<ll>(27));
  vector<ll> zenkai(27); /*各nameコンテストが前回行われた日*/

  for (ll name = 1; name <= 26; name++)
    cin >> c.at(name);

  for (ll day = 1; day <= D; day++) {
    for (ll name = 1; name <= 26; name++) {
      cin >> s.at(day).at(name);
    }
  }
  vector<ll> t(D + 1);

  /*for (ll day = 1; day <= D; day++) {
          cin >> t.at(day);
  }*/

  for (ll name = 1; name <= 26; name++) {
    zenkai.at(name) = 0;
  }

  ll an = 0; /*満足度*/
  ll n = 0;  /*各日のコンテスト仮*/
  for (ll day = 1; day <= D; day++) {
    ll karimax = an - 999999999999;
    n = -1;
    for (ll kariname = 1; kariname <= 26; kariname++) {
      ll karian = an;

      karian += s.at(day).at(kariname);
      /*zenkai.at(t.at(day)) = day;*/

      for (ll name = 1; name <= 26; name++) {
        if (name != kariname) {
          an -= c.at(name) * (day - zenkai.at(name));
        }
      }

      if (karian >= karimax) {
        n = kariname;
        karimax = karian;
      }
    }
    if (n == -1) {
      n = 1;
    }
    an += s.at(day).at(n);
    zenkai.at(n) = day;

    for (ll name = 1; name <= 26; name++) {

      an -= c.at(name) * (day - zenkai.at(name));
    }

    cout << n << endl;
  }
  /*cout << an << endl;*/
}

Error: WA

Fixed submission:

#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <cstdint> // int64_t, int*_t
#include <cstdio>  // printf
#include <cstdlib>
#include <deque> // deque
#include <iomanip>
#include <iostream>
#include <limits>
#include <map> // map
#include <numeric>
#include <queue> // queue, priority_queue
#include <set>   // set
#include <stack> // stack
#include <stdio.h>
#include <string>        // string, to_string, stoi
#include <tuple>         // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) { return max(max(a, b), c); }
ll Min(ll(a), ll(b), ll(c)) { return min(min(a, b), c); }

int main() {
  ll D;
  cin >> D;
  vector<ll> c(27);
  vector<vector<ll>> s(D + 1, vector<ll>(27));
  vector<ll> zenkai(27);

  for (ll name = 1; name <= 26; name++)
    cin >> c.at(name);
  for (ll day = 1; day <= D; day++)
    for (ll name = 1; name <= 26; name++)
      cin >> s.at(day).at(name);
  vector<ll> t(D + 1);

  /*for (ll day = 1; day <= D; day++) {
          cin >> t.at(day);
  }*/

  for (ll name = 1; name <= 26; name++) {
    zenkai.at(name) = 0;
  }

  ll an = 0;
  ll n = 0;
  for (ll day = 1; day <= D; day++) {
    ll karimax = -99999999;
    n = -1;
    for (ll kariname = 1; kariname <= 26; kariname++) {
      ll karian = an;

      karian += s.at(day).at(kariname);
      /*zenkai.at(t.at(day)) = day;*/

      for (ll name = 1; name <= 26; name++) {
        if (name != kariname) {
          an -= c.at(name) * (day - zenkai.at(name));
        }
      }

      if (karian >= karimax) {
        n = kariname;
        karimax = karian;
      }
    }
    an += s.at(day).at(n);
    zenkai.at(n) = day;

    for (ll name = 1; name <= 26; name++) {

      an -= c.at(name) * (day - zenkai.at(name));
    }

    cout << n << endl;
  }
  /*cout << an << endl;*/
}