Problem p02618 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

int main() {
  int d;
  cin >> d;
  vector<int> c26(26);
  vector<vector<int>> si(d, vector<int>(26));
  for (int i = 0; i < 26; ++i)
    cin >> c26[i];
  for (int i = 0; i < d; ++i)
    for (int j = 0; j < 26; ++j)
      cin >> si[i][j];

  vector<vector<int>> koho(d);
  for (int i = 0; i < 26; ++i) {
    int hindo;
    if (c26[i] <= 10)
      hindo = 100;
    else if (c26[i] <= 30)
      hindo = 50;
    else if (c26[i] <= 60)
      hindo = 20;
    else
      hindo = 10;

    int j = 0;
    while (j < d - 1) {
      int cnt = 0;
      int mxday = min(j + hindo, d - 1);
      for (int k = mxday; k > j; --k) {
        if (si[k][i] >= 13333) {
          koho[k].push_back(i);
          ++cnt;
          for (int l = j + 1; l <= k; ++l) {
            si[l][i] += (l - j) * (l - j) * c26[i];
          }
          j = k;
          break;
        }
      }
      if (cnt == 0) {
        for (int l = j + 1; l <= mxday; ++l) {
          si[l][i] += (l - j) * (l - j) * c26[i];
        }
        j = mxday;
      }
    }
  }

  vector<int> ans(d);
  for (int i = 0; i < d; ++i) {
    vector<P> koho2(0);
    if (koho[i].size() == 0) {
      for (int j = 0; j < 26; ++j) {
        koho2.push_back(make_pair(si[i][j], j));
      }
    } else {
      for (int n : koho[i]) {
        koho2.push_back(make_pair(si[i][n], n));
      }
    }
    sort(koho2.begin(), koho2.end());
    reverse(koho2.begin(), koho2.end());
    ans[i] = koho2[0].second;
  }
  for (int i = 0; i < d; ++i) {
    cout << ans[i] + 1 << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

int main() {
  int d;
  cin >> d;
  vector<int> c26(26);
  vector<vector<int>> si(d, vector<int>(26));
  for (int i = 0; i < 26; ++i)
    cin >> c26[i];
  for (int i = 0; i < d; ++i)
    for (int j = 0; j < 26; ++j)
      cin >> si[i][j];

  vector<vector<int>> koho(d);
  for (int i = 0; i < 26; ++i) {
    int hindo;
    if (c26[i] <= 10)
      hindo = 60;
    else if (c26[i] <= 30)
      hindo = 20;
    else if (c26[i] <= 60)
      hindo = 10;
    else
      hindo = 7;

    int j = 0;
    while (j < d) {
      int cnt = 0;
      for (int k = j + hindo; k > j && k < d; --k) {
        if (si[i][k] >= 10000) {
          koho[k].push_back(i);
          ++cnt;
        }
        if (cnt == 2) {
          for (int l = j + 1; l <= k; ++l) {
            si[l][i] += (l - j) * c26[i];
            if (l >= k)
              si[j][i] -= (l - k) * c26[i];
          }
          j = k;
          break;
        }
      }
      if (cnt == 0) {
        int mxday = min(j + hindo, d - 1);
        for (int l = j + 1; l <= mxday; ++l) {
          si[l][i] += (l - j) * c26[i];
        }
        koho[mxday].push_back(i);
        j = min(j + hindo, d);
      }
    }
  }

  vector<int> ans(d);
  for (int i = 0; i < d; ++i) {
    vector<P> koho2(0);
    if (koho[i].size() == 0) {
      for (int j = 0; j < 26; ++j) {
        koho2.push_back(make_pair(si[i][j], j));
      }
    } else {
      for (int n : koho[i]) {
        koho2.push_back(make_pair(si[i][n], n));
      }
    }
    sort(koho2.begin(), koho2.end());
    reverse(koho2.begin(), koho2.end());
    ans[i] = koho2[0].second;
  }

  for (int i = 0; i < d; ++i) {
    cout << ans[i] + 1 << endl;
  }
}