B - Various distances 解説 /

実行時間制限: 2 sec / メモリ制限: 1024 MB

配点 : 200

問題文

N 次元空間内の点 (x_1,\ldots,x_N) が与えられます。

原点からこの点までの、マンハッタン距離、ユークリッド距離、チェビシェフ距離をそれぞれ求めてください。 ただし、それぞれの距離は次のように計算されます。

  • マンハッタン距離: |x_1|+\ldots+|x_N|
  • ユークリッド距離: \sqrt{|x_1|^2+\ldots+|x_N|^2}
  • チェビシェフ距離: \max(|x_1|,\ldots,|x_N|)

制約

  • 1 \leq N \leq 10^5
  • -10^5 \leq x_i \leq 10^5
  • 入力は全て整数

入力

入力は以下の形式で標準入力から与えられる。

N
x_1 \ldots x_N

出力

原点から与えられた点までの、マンハッタン距離、ユークリッド距離、チェビシェフ距離をそれぞれこの順に改行区切りで出力せよ。 正しい値との絶対誤差または相対誤差が 10^{-9} 以下であれば正解とみなされる。


入力例 1

2
2 -1

出力例 1

3
2.236067977499790
2

それぞれ次のように計算されます。

  • マンハッタン距離: |2|+|-1|=3
  • ユークリッド距離: \sqrt{|2|^2+|-1|^2}=2.236067977499789696\ldots
  • チェビシェフ距離: \max(|2|,|-1|)=2

入力例 2

10
3 -1 -4 1 -5 9 2 -6 5 -3

出力例 2

39
14.387494569938159
9

Score : 200 points

Problem Statement

Given is a point (x_1,\ldots,x_N) in an N-dimensional space.

Find the Manhattan distance, Euclidian distance, and Chebyshev distance between this point and the origin. Here, each of them is defined as follows:

  • The Manhattan distance: |x_1|+\ldots+|x_N|
  • The Euclidian distance: \sqrt{|x_1|^2+\ldots+|x_N|^2}
  • The Chebyshev distance: \max(|x_1|,\ldots,|x_N|)

Constraints

  • 1 \leq N \leq 10^5
  • -10^5 \leq x_i \leq 10^5
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
x_1 \ldots x_N

Output

Print the Manhattan distance, Euclidian distance, and Chebyshev distance between the given point and the origin, each in its own line. Each value in your print will be accepted when its absolute or relative error from the correct value is at most 10^{-9}.


Sample Input 1

2
2 -1

Sample Output 1

3
2.236067977499790
2

Each of the distances is computed as follows:

  • The Manhattan distance: |2|+|-1|=3
  • The Euclidian distance: \sqrt{|2|^2+|-1|^2}=2.236067977499789696\ldots
  • The Chebyshev distance: \max(|2|,|-1|)=2

Sample Input 2

10
3 -1 -4 1 -5 9 2 -6 5 -3

Sample Output 2

39
14.387494569938159
9