All problems

Projecting One Vector Onto Another

hardPythonNumPyLinear Algebra

A race committee tracks a dinghy against the course line to the next mark. The boat's run over the last hour is recorded as one figure per axis of the survey grid, and the course line is recorded the same way — but the course line's figures only say which way it points, and how long that record happens to be means nothing. The committee wants a single distance: how far along the course line the boat actually got. Progress in the wrong direction counts against the boat, so a run that carried it back down the line is reported as a negative distance.

Task: Print how far the dinghy got along the course line.

Input

Three lines. The first holds an integer n, the number of axes. The second holds the boat's run, n figures separated by single spaces. The third holds the course line, n figures in the same axis order. The course line is never all zeros.

Output

One line holding the distance along the course line, signed, written with exactly two decimal places, in the same units as the boat's run.

Example:

Input:
2
3 4
1 0

Output:
3.00

Sign in to solve this problem

Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.

Sign in

Discussion

Sign in to join the discussion — reading is open to everyone.

Loading comments…