Академический Документы
Профессиональный Документы
Культура Документы
Home (/) » Compete (/contests/) » February Challenge 2018 (/FEB18?order=desc&sortBy=successful_submissions) » Car-pal Tunnel
Tweet
(https://twitter.com
Like Share 22 people like this. Be the first of your friends.
/share)
Each tunnel contains a toll booth. In the i-th tunnel (1 ≤ i ≤ N), processing a car at the toll
booth takes Ai seconds. Only one car can be processed at the same time. If there are
multiple cars in the tunnel, they all have to wait for the first car to be processed;
afterwards, the first car exits the tunnel, the second car starts being processed and all
remaining cars have to wait again, etc. Whenever a car arrives in a tunnel, it has to wait
at that tunnel's toll booth until all previous cars have been processed and then get
processed itself.
The road and the tunnels are too narrow, so cars can't overtake each other at any time
during the journey.
Chef is after Reziba once again. Reziba's car is the first car to enter the tunnels, while
Chef's car is the last car to enter the tunnels.
Compute the final delay (in seconds) between the first (Reziba's) car and the last
(Chef's) car immediately after Chef's car exits the last tunnel, i.e. after all the cars have
passed through the tunnels. This delay is equal to the distance between the first and the
last car divided by the cars' velocity, or equivalently to the difference between the times
when the last car and the first car exit the last tunnel.
Input
The first line of the input contains a single integer T denoting the number of test
cases. The description of T test cases follows.
The first line of each test case contains a single integer N denoting the number of
tunnels.
The second line contains N space-separated integers A1, A2, ..., AN denoting the
time taken for processing a car at each toll booth.
The third line contains three space-separated integers C, D and S.
Output
For each test case, print a single line containing one real number — the time delay
between the first and last car after all the cars have passed through all the tunnels. Your
1 of 3 08/02/18, 9:29 PM
answer will be considered correct if its absolute error is less than 10-6.
Car-pal Tunnel | CodeChef
Constraints https://www.codechef.com/FEB18/problems/CA...
1 ≤ T ≤ 100
1 ≤ N ≤ 105
1 ≤ Ai ≤ 109 for each valid i
2 ≤ C ≤ 106
1 ≤ D, S ≤ 109
Subtasks
Subtask #1:
1 ≤ N ≤ 1,000
C=2
Example
Input:
2
3
2 2 2
3 5 5
2
3 2
2 1 1
Output:
4.000000000
3.000000000
Explanation
Example case 1: Each car takes 5/5 = 1 second to go from one tunnel to the next
tunnel.
Since each car has to wait for equally long (2 seconds) in each tunnel, the delay
between every two consecutive cars exiting each tunnel is 2 seconds.
As there are 3 cars, the total time delay between the first and the last car after the last
tunnel is 4 seconds.
Languages: ADA, ASM, BASH, BF, C, CAML, CLOJ, CLPS, COB, CPP 4.3.2,
CPP 6.3, CPP14, CS2, D, ERL, FORT, FS, GO, HASK, ICK, ICON,
JAVA, JS, kotlin, LISP clisp, LISP sbcl, LUA, NEM, NICE, NODEJS,
PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYPY,
PYTH, PYTH 3.5, RUBY, rust, SCALA, SCM chicken, SCM guile,
SCM qobi, ST, swift, TCL, TEXT, WSPC
Comments
2 of 3 08/02/18, 9:29 PM
Car-pal Tunnel | CodeChef https://www.codechef.com/FEB18/problems/CA...
© 2009 Directi Group (http://directi.com). All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs (http://www.sphere-research.com)
In order to report copyright violations of any kind, send in an email to copyright@codechef.com (mailto:copyright@codechef.com)
(http://directi.com)
FAQ's (https://www.codechef.com/wiki/faq)
Initiatives
3 of 3 08/02/18, 9:29 PM