What's wrong with this code

The Morning Commute - successfull submissions = 706 , codechef easy. I am geeting wrong answer for my code on submitting.I have tried the sample test cases given and also some of my own and got correct answer,hence not getting where is the mistake.Plzzz help,it would take a long on comments page,hence i posted here. here is my code

include
include<stdio.h>
using namespace std;

int main(){ int i,n;

int time = 0,reach,t = 0,cases; scanf("%i",&cases);

while(t < cases){ scanf("%i",&n); int x[n],l[n],f[n];

for(i = 0 ; i < n ; i++){ scanf("%i",&x[i]); scanf("%i",&l[i]); scanf("%i",&f[i]); }

for(i = 0 ; i <= n - 2 ; i++){ //time spent in waiting for first train if(i == 0){ time = time + x[i]; }

//time for travelling (i + 1)th line
time = time + l[i];

//reach is time when chef reaches the next station,its like clock time with no bounds.eg-4:00,13:00,17;00,25:00etc.//
reach = x[i] + l[i];

 if(reach > x[i + 1]){
   do{
    x[i + 1] = x[i + 1] + f[i + 1];
 }while(reach > x[i + 1]);

}

//time for wait before the next train comes
time = time + x[i + 1] - reach;

//travel time for the last line
if(i == n - 2){
time = time + l[n - 1];
break;
}
}

printf("%i\n",time); t++,time = 0; } return 0; }