結果

問題 No.609 Noelちゃんと星々
ユーザー htensaihtensai
提出日時 2019-11-14 13:27:49
言語 Java21
(openjdk 21)
結果
AC  
実行時間 685 ms / 2,000 ms
コード長 405 bytes
コンパイル時間 2,087 ms
コンパイル使用メモリ 78,012 KB
実行使用メモリ 65,392 KB
最終ジャッジ日時 2023-10-21 19:59:00
合計ジャッジ時間 17,795 ms
ジャッジサーバーID
(参考情報)
judge9 / judge10
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 591 ms
59,908 KB
testcase_01 AC 478 ms
62,096 KB
testcase_02 AC 411 ms
61,904 KB
testcase_03 AC 468 ms
62,024 KB
testcase_04 AC 365 ms
61,936 KB
testcase_05 AC 640 ms
64,076 KB
testcase_06 AC 650 ms
62,200 KB
testcase_07 AC 526 ms
62,056 KB
testcase_08 AC 297 ms
62,284 KB
testcase_09 AC 438 ms
62,132 KB
testcase_10 AC 546 ms
61,960 KB
testcase_11 AC 556 ms
62,000 KB
testcase_12 AC 580 ms
62,028 KB
testcase_13 AC 323 ms
62,028 KB
testcase_14 AC 255 ms
61,004 KB
testcase_15 AC 631 ms
62,060 KB
testcase_16 AC 680 ms
64,104 KB
testcase_17 AC 599 ms
62,132 KB
testcase_18 AC 423 ms
62,000 KB
testcase_19 AC 630 ms
62,156 KB
testcase_20 AC 646 ms
65,392 KB
testcase_21 AC 685 ms
64,580 KB
testcase_22 AC 647 ms
64,620 KB
testcase_23 AC 673 ms
64,828 KB
testcase_24 AC 656 ms
64,872 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
		    arr[i] = sc.nextInt();
		}
		Arrays.sort(arr);
		long total = 0;
		int m = arr[n / 2];
		for (int i = 0; i < n; i++) {
		    total += Math.abs(arr[i] - m);
		}
		System.out.println(total);
	}
}
0