Company: Accenture_20may
Difficulty: medium
Consider the positive X-Axis as a straight road on which N houses are located. On a rainy day, M people are out on a walk. When the rain starts, each person runs towards the house nearest to them, so that they do not get wet. You are given the position of each house, the width of each house and the position of each person when the rain started. Your task is to find the sum of the distances travelled by all the people to reach the house nearest to them. Notes If a person is already inside a house, the distance travelled by that person is 0 . A person can run in both the forward and the backward direction to reach the house nearest to them. If a house is located at position X and its width is W , then a person is considered to be inside that house only if the person's position lies in the range [X, X + W - 1] (inclusive). Houses may overlap each other. Input Format N X1 X2 ... XN W1 W2 ... WN M P1 P2 ... PM Line 1: N , the number of houses. Line 2: N space-separated integers, the positio