

Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 点
問題文
東西方向に伸びる道路に沿って 社の神社と 軒の寺が建っています。 西から 社目の神社は道路の西端から メートルの地点に、西から 軒目の寺は道路の西端から メートルの地点にあります。
以下の 個の問いに答えてください。
問 (): 道路の西端から メートルの地点から出発して道路上を自由に移動するとき、神社一社と寺一軒を訪れるのに必要な最小の移動距離は何メートルか? (必要数を超えた数の寺社を通過してもよい。)
制約
- はすべて異なる。
- 入力される値はすべて整数である。
入力
入力は以下の形式で標準入力から与えられる。
出力
行出力せよ。 行目に問 への答えを出力すること。
入力例 1Copy
2 3 4 100 600 400 900 1000 150 2000 899 799
出力例 1Copy
350 1400 301 399
社の神社と 軒の寺があり、神社は道路の西端から メートルの地点に、寺は道路の西端から メートルの地点にあります。
- 問 : 道路の西端から メートルの地点から出発する場合、まず西に メートル進んで神社を訪れ、次に東に メートル進んで寺を訪れるのが最適です。
- 問 : 道路の西端から メートルの地点から出発する場合、まず西に メートル進んで寺を訪れ、次に西に メートル進んで神社を訪れるのが最適です。途中で寺をもう一軒通過しますが、構いません。
- 問 : 道路の西端から メートルの地点から出発する場合、まず東に メートル進んで寺を訪れ、次に西に メートル進んで神社を訪れるのが最適です。
- 問 : 道路の西端から メートルの地点から出発する場合、まず西に メートル進んで神社を訪れ、次に西に メートル進んで寺を訪れるのが最適です。
入力例 2Copy
1 1 3 1 10000000000 2 9999999999 5000000000
出力例 2Copy
10000000000 10000000000 14999999998
道路は長く、 ビット整数に収まらない距離を移動する必要があるかもしれません。
Score : points
Problem Statement
Along a road running in an east-west direction, there are shrines and temples. The -th shrine from the west is located at a distance of meters from the west end of the road, and the -th temple from the west is located at a distance of meters from the west end of the road.
Answer the following queries:
- Query (): If we start from a point at a distance of meters from the west end of the road and freely travel along the road, what is the minimum distance that needs to be traveled in order to visit one shrine and one temple? (It is allowed to pass by more shrines and temples than required.)
Constraints
- are all different.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print lines. The -th line should contain the answer to the -th query.
Sample Input 1Copy
2 3 4 100 600 400 900 1000 150 2000 899 799
Sample Output 1Copy
350 1400 301 399
There are two shrines and three temples. The shrines are located at distances of meters from the west end of the road, and the temples are located at distances of meters from the west end of the road.
- Query : If we start from a point at a distance of meters from the west end of the road, the optimal move is first to walk meters west to visit a shrine, then to walk meters east to visit a temple.
- Query : If we start from a point at a distance of meters from the west end of the road, the optimal move is first to walk meters west to visit a temple, then to walk meters west to visit a shrine. We will pass by another temple on the way, but it is fine.
- Query : If we start from a point at a distance of meters from the west end of the road, the optimal move is first to walk meter east to visit a temple, then to walk meters west to visit a shrine.
- Query : If we start from a point at a distance of meters from the west end of the road, the optimal move is first to walk meters west to visit a shrine, then to walk meters west to visit a temple.
Sample Input 2Copy
1 1 3 1 10000000000 2 9999999999 5000000000
Sample Output 2Copy
10000000000 10000000000 14999999998
The road is quite long, and we may need to travel a distance that does not fit into a -bit integer.