[Solution] Two Trains CodeChef Solution | Solution CodeChef
Problem
There are trains and and stations in a line from to in order. There is also an array of length such that denotes the amount of time any train takes to go from the -th station to the -th station.
Initially, both trains are at station . Train departs from station and stops directly at station . For safety purposes, it is maintained that train cannot depart from station unless train has already reached station .
Find the minimum time after which train reaches station , once train departs from station .
Input Format
- The first line of input will contain a single integer , denoting the number of test cases.
- Each test case consists of two lines of input.
- The first line of each test case contains an integer , denoting number of stations.
- The next line contains space-separated integers, .
Output Format
For each test case, output on a new line the minimum time after which train reaches station .
Explanation:
Test case : reaches station at and at this time departs from station and reaches station at .
Test case : Following is the timeline of two trains-
- At , reaches station and departs from station .
- At , reaches station but has not yet reached station , so train will wait at station .
- At , reaches station and departs from station .
- At , train reaches station .
No comments:
Post a Comment