Walking
InterviewTime limit2sMemory limit128 MB
Compute the minimum time to walk from (0,0) to (X,Y) on a grid where straight moves cost W and diagonal moves cost S.
Problem
Sejun wants to walk home from school. The city is an infinite grid: there is a vertical road at every integer x-coordinate and a horizontal road at every integer y-coordinate. Sejun starts at (0, 0), and his home is at (X, Y).
In one move, he can either move one block horizontally or vertically along the roads, or cross one block diagonally.
Find the minimum time needed for Sejun to get home.
Input
The first line contains four integers X Y W S. X and Y are the coordinates of the home. W is the time needed to move one block along a road, and S is the time needed to cross one block diagonally.
X and Y are integers between 0 and 1,000,000,000 inclusive. W and S are integers between 1 and 10,000 inclusive.
Output
Print the minimum time needed to get home.