Problem p03475 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<long long> VLL;
typedef vector<pair<int, int>> VP;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define FOR(i, k, n) for (int i = (k); i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.begin(), a.end(), greater<int>()
#define ROT(a) a.begin(), a.begin() + 1, a.end()
#define RROT(a) a.begin(), a.end() - 1, a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9 + 7;
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> T gcd(T a, T b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
// cout << 'H' << endl;
/*--------------------------------------------*/

int N;

int main() {
  // cout.precision(10);
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> N;
  vector<int> c(N - 1), s(N - 1), f(N - 1); // c:かかる時間,s:発車時刻,f:発車間隔

  vector<vector<int>> t(N - 1);

  rep(i, N - 1) {
    cin >> c[i] >> s[i] >> f[i];
    rep(j, 150000) { t[i].PB(s[i] + j * f[i]); }
  }

  int time = 0, now = 0;

  rep(i, N - 1) { // i: iからのスタート(0 ~ N-2)
    // now以降で初めて列車iが発車する時刻を求める
    now = t[i][0];
    for (int j = i + 1; j < N - 1; j++) { // j: 通過点(i+1 ~ N-2)
      now += c[j - 1];                    //
      auto itr =
          lower_bound(ALL(t[j]), now); // t[j]のなかでnow以上で最小のものを探す
      now = *itr;
    }
    cout << now + c[N - 2] << endl;
  }
  cout << 0 << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<long long> VLL;
typedef vector<pair<int, int>> VP;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define FOR(i, k, n) for (int i = (k); i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.begin(), a.end(), greater<int>()
#define ROT(a) a.begin(), a.begin() + 1, a.end()
#define RROT(a) a.begin(), a.end() - 1, a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9 + 7;
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> T gcd(T a, T b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
// cout << 'H' << endl;
/*--------------------------------------------*/

int N;

int main() {
  // cout.precision(10);
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> N;
  vector<int> c(N - 1), s(N - 1), f(N - 1); // c:かかる時間,s:発車時刻,f:発車間隔

  vector<vector<int>> t(N - 1);

  rep(i, N - 1) {
    cin >> c[i] >> s[i] >> f[i];
    rep(j, 130000) { t[i].PB(s[i] + j * f[i]); }
  }

  int time = 0, now = 0;

  rep(i, N - 1) { // i: iからのスタート(0 ~ N-2)
    // now以降で初めて列車iが発車する時刻を求める
    now = t[i][0];
    for (int j = i + 1; j < N - 1; j++) { // j: 通過点(i+1 ~ N-2)
      now += c[j - 1];                    //
      auto itr =
          lower_bound(ALL(t[j]), now); // t[j]のなかでnow以上で最小のものを探す
      now = *itr;
    }
    cout << now + c[N - 2] << endl;
  }
  cout << 0 << endl;
}