結果

問題 No.609 Noelちゃんと星々
ユーザー tentententen
提出日時 2020-09-05 19:58:16
言語 Java21
(openjdk 21)
結果
AC  
実行時間 642 ms / 2,000 ms
コード長 421 bytes
コンパイル時間 4,975 ms
コンパイル使用メモリ 72,332 KB
実行使用メモリ 62,396 KB
最終ジャッジ日時 2023-08-19 12:59:45
合計ジャッジ時間 20,466 ms
ジャッジサーバーID
(参考情報)
judge12 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 562 ms
61,168 KB
testcase_01 AC 439 ms
60,480 KB
testcase_02 AC 381 ms
60,544 KB
testcase_03 AC 429 ms
60,336 KB
testcase_04 AC 330 ms
60,360 KB
testcase_05 AC 613 ms
61,800 KB
testcase_06 AC 619 ms
60,772 KB
testcase_07 AC 501 ms
60,296 KB
testcase_08 AC 276 ms
60,512 KB
testcase_09 AC 404 ms
60,612 KB
testcase_10 AC 510 ms
60,628 KB
testcase_11 AC 504 ms
60,536 KB
testcase_12 AC 544 ms
60,584 KB
testcase_13 AC 312 ms
61,056 KB
testcase_14 AC 235 ms
59,852 KB
testcase_15 AC 572 ms
58,768 KB
testcase_16 AC 640 ms
60,828 KB
testcase_17 AC 557 ms
60,652 KB
testcase_18 AC 409 ms
60,564 KB
testcase_19 AC 569 ms
60,796 KB
testcase_20 AC 613 ms
62,328 KB
testcase_21 AC 642 ms
62,072 KB
testcase_22 AC 610 ms
62,152 KB
testcase_23 AC 642 ms
62,152 KB
testcase_24 AC 607 ms
62,396 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 ans = 0;
    	for (int i = 0; i < n; i++) {
    	    ans += Math.abs(arr[i] - arr[n / 2]);
    	}
    	System.out.println(ans);
	}
}
0