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

/*
    Author - Param Kothari
    Ah shit, here we go again
*/

#include <bits/stdc++.h>

using namespace std;

#define IOS                                                                    \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define pb push_back
#define mk make_pair

typedef long long ll;
typedef long double ld;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void solve() {
  int d;
  cin >> d;
  assert(d == 365);
  vector<int> c(26);
  for (int i = 0; i < 26; i++) {
    cin >> c[i];
  }
  vector<vector<int>> s(d, vector<int>(26));
  for (int i = 0; i < d; i++) {
    for (int j = 0; j < 26; j++) {
      cin >> s[i][j];
    }
  }
  int tries = 5000;
  int ans = 0;
  vector<int> fin;
  for (int tt = 0; tt < tries; tt++) {
    vector<int> t(d), satisfaction(d);
    for (int i = 0; i < d; i++) {
      t[i] = rng() % 26;
      t[i]++;
    }
    int sat = 0;
    vector<int> last(26);
    for (int i = 0; i < d; i++) {
      last[t[i] - 1] = i + 1;
      sat += s[i][t[i] - 1];
      for (int j = 0; j < 26; j++) {
        sat -= (i + 1 - last[j]) * c[j];
      }
      satisfaction[i] = sat;
    }
    // for(int i = 0; i < d; i++){
    //     cout << satisfaction[i] << "\\n";
    // }
    // for(int i = 0; i < d; i++){
    //     cout << t[i] << "\\n";
    // }
    int res = max(1000000 + satisfaction[d - 1], 0);
    if (res > ans || tt == 0) {
      ans = res;
      fin = t;
    }
  }
  for (int i = 0; i < d; i++) {
    cout << fin[i] << "\\n";
  }
  // cout << ans << "\\n";
  return;
}

int main() {
  IOS;
  int t = 1;
  // cin >> t;
  for (int i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}

Error: WA

Fixed submission:

/*
    Author - Param Kothari
    Ah shit, here we go again
*/

#include <bits/stdc++.h>

using namespace std;

#define IOS                                                                    \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define pb push_back
#define mk make_pair

typedef long long ll;
typedef long double ld;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void solve() {
  int d;
  cin >> d;
  vector<int> c(26);
  for (int i = 0; i < 26; i++) {
    cin >> c[i];
  }
  vector<vector<int>> s(d, vector<int>(26));
  for (int i = 0; i < d; i++) {
    for (int j = 0; j < 26; j++) {
      cin >> s[i][j];
    }
  }
  int tries = 5000;
  int ans = 0;
  vector<int> fin;
  for (int tt = 0; tt < tries; tt++) {
    vector<int> t(d), satisfaction(d);
    for (int i = 0; i < d; i++) {
      t[i] = rng() % 26;
      t[i]++;
    }
    int sat = 0;
    vector<int> last(26);
    for (int i = 0; i < d; i++) {
      last[t[i] - 1] = i + 1;
      sat += s[i][t[i] - 1];
      for (int j = 0; j < 26; j++) {
        sat -= (i + 1 - last[j]) * c[j];
      }
      satisfaction[i] = sat;
    }
    // for(int i = 0; i < d; i++){
    //     cout << satisfaction[i] << "\\n";
    // }
    // for(int i = 0; i < d; i++){
    //     cout << t[i] << "\\n";
    // }
    int res = max(1000000 + satisfaction[d - 1], 0);
    if (res > ans) {
      ans = res;
      fin = t;
    }
  }
  for (int i = 0; i < d; i++) {
    cout << fin[i] << "\\n";
  }
  // cout << ans << "\\n";
  return;
}

int main() {
  IOS;
  int t = 1;
  // cin >> t;
  for (int i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}