Marks :20
: 11 | : 2
It is the apple harvest season. Alice and Bob are all set to pluck them from their farm. However, due to a certain incident, the apples are now falling down one after another. The farm in an infinite large 2D plane.
Given the initial coordinates of Alice $$$(A_x,A_y)$$$ and initial coordinates of Bob $$$(B_x,B_y)$$$ and also the coordinates where N apples will fall, you need to calculate the minimum Manhattan distance covered in total by Alice and Bob together in order to catch all apples.
The first line consists of an integer $$$1\le N \le 10^{3}$$$ denoting number of apples
The second line contain two space separated integers $$$-10^{9}\le A_x \le 10^{9}$$$ and $$$-10^{9}\le A_y \le 10^{9}$$$ representing Alice's initial coordinates.
The third line contain two space separated integers $$$-10^{9}\le B_x \le 10^{9}$$$ and $$$-10^{9}\le B_y \le 10^{9}$$$ representing Bob's initial coordinates.
$$$N$$$ line follow where $$$1\le i \le N$$$ line consist of two space separated integers $$$-10^{9}\le X_i \le 10^{9}$$$ representing $$$-10^{9}\le Y_i \le 10^{9}$$$
Output the minimum distance travelled to cover all the apples.
2 0 5 2 2 0 3 2 3
3
5 -5 4 1 0 0 10 -11 5 12 1 0 9 -10 8
57
In first test case $$$N=2$$$ and $$$A_x=0,A_y=5$$$ and $$$B_x=2,B_y=2$$$ and first apple at $$$(0,3)$$$ and second apple at $$$(2,3)$$$
The first apple can be caught by Alice with manhattan distance $$$|0-0|+|5-3|=2$$$ units.
The second apple can be caught by Bob with manhattan distance $$$|2-2|+|3-2|=1$$$ units.
Hence total answer is $$$3$$$ units.
You need to login to view your submissions.
You need to login to view all submissions.
Result : Executed
Feel something is wrong with the test cases?
Result : Accepted
Test Cases :
But to Run or Submit the Problem, you need to Log In.
Continue to Log InYour challenge has been submitted successfully.
You will get a response soon via WhatsApp or Email.
Do let us know your issue.