Why are my getting the wrong answer?

I don’t know why I’m getting a wrong answer for “The Morning Commute”. It works on all of the examples they provided. Please help me!

The Problem: http://www.codechef.com/problems/COMMUTE

My Code:

  #include <iostream>
  using namespace std;int main() {
int t, n;
cin >> t;
while (t--){
	cin >> n;
	int ** schedule;
	schedule = new int*[n];
	for (int a = 0; a < n; a++){
		schedule[a] = new int[3];
		cin >> schedule[a][0] >> schedule[a][1] >> schedule[a][2];
	}
	int current_time, total_time;
	current_time = 0;
	total_time = 0;
	for (int a = 0; a < n; a++){
		if (current_time < schedule[a][0]){
			total_time += schedule[a][0] - current_time;
			current_time = schedule[a][0];
		}
		else {
			if (current_time%schedule[a][2] != 0){
				total_time += schedule[a][2] - (current_time % schedule[a][2]);
				current_time += schedule[a][2] - (current_time % schedule[a][2]);
			}
		}
		total_time += schedule[a][1];
		current_time += schedule[a][1];
	}
	cout << total_time << endl;
}
return 0;

}

Sorry if the code isn’t formatted properly.
My solution is here: http://www.codechef.com/viewsolution/3137758

on 1st station(i=0), just add x+l, starting time and time between 1st and 2nd station. however, on following stations, if chef arrived earlier than trains departure time(a<x), then chef waits till train depart(a=x). if chef has missed the train(a>x), then wait till next train depart(x=x+f). then update time(a=x; a=a+l;). follow same approach till last station. that is all.

wish not to post code, but i have no other option to be more helpful: http://ideone.com/pHohIL

btw, to compile faster use scanf printf