Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 40121

Why are my getting the wrong answer?

$
0
0

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; }


Viewing all articles
Browse latest Browse all 40121

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>