Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A cab company is recently planning to launch electric vehicles. Each electric vehicle contains swappable battery which needs to be replaced at some moment of

A cab company is recently planning to launch electric vehicles. Each electric vehicle contains swappable battery which needs to be replaced at some moment of time. At a particular moment there are n drivers and k batteries on a straight line. Every driver wants to go to a pickup location which is located on the line as well. To do that, he needs to reach battery location, replace the battery and then go to the pickup location. Once a battery is taken by somebody, it couldn't be taken by anybody else.

You need to determine the minimum time needed for all n drivers to get to the pickup location after swapping batteries. Assume that drivers move a unit distance per 1 second. If two drivers reach a battery at the same time, then only one of them can take the battery. A person can pass through a point with a battery without taking it.

For test-case #1:

  • Driver will go from location #11 to battery #2 at location #7 (4sec)
  • Driver will go from location #7 to pickup location #10 (3sec)

Total of 7 sec

  • [execution time limit] 2 seconds (cpp)

  • [input] array.integer drivers

    Length = n; where n <= 1000

    n distinct integers are a1,a2,...,an (1ai10^9) positions in which drivers are located initially. The positions are given in arbitrary order.

  • [input] array.integer batteries

    Length = k; where nk2000

    k distinct integers are b1,b2,...,bk (1bj10^9) positions of the batteries. The positions are given in arbitrary order.

  • [input] integer p

    the pickup location. (1p10^9)

    Note that there can't be more than one person or more than one battery in the same point. A person and a battery can be located in the same point.

  • [output] integer64

    • Print the minimum time (in seconds) needed for all n drivers to reach the pickup location after swapping the batteries

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions