結果

問題 No.609 Noelちゃんと星々
ユーザー Tsukasa_TypeTsukasa_Type
提出日時 2018-02-28 23:14:28
言語 Java21
(openjdk 21)
結果
AC  
実行時間 599 ms / 2,000 ms
コード長 484 bytes
コンパイル時間 2,388 ms
コンパイル使用メモリ 73,092 KB
実行使用メモリ 62,880 KB
最終ジャッジ日時 2023-08-24 16:29:25
合計ジャッジ時間 15,130 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 528 ms
61,756 KB
testcase_01 AC 381 ms
61,676 KB
testcase_02 AC 310 ms
61,044 KB
testcase_03 AC 368 ms
61,560 KB
testcase_04 AC 266 ms
60,692 KB
testcase_05 AC 586 ms
61,720 KB
testcase_06 AC 548 ms
61,288 KB
testcase_07 AC 430 ms
61,720 KB
testcase_08 AC 234 ms
60,800 KB
testcase_09 AC 341 ms
62,880 KB
testcase_10 AC 480 ms
61,780 KB
testcase_11 AC 461 ms
61,840 KB
testcase_12 AC 518 ms
61,428 KB
testcase_13 AC 244 ms
60,208 KB
testcase_14 AC 206 ms
59,316 KB
testcase_15 AC 556 ms
61,340 KB
testcase_16 AC 599 ms
62,144 KB
testcase_17 AC 494 ms
61,956 KB
testcase_18 AC 311 ms
60,964 KB
testcase_19 AC 549 ms
61,104 KB
testcase_20 AC 549 ms
62,840 KB
testcase_21 AC 577 ms
62,280 KB
testcase_22 AC 594 ms
62,016 KB
testcase_23 AC 575 ms
61,476 KB
testcase_24 AC 574 ms
61,580 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import static java.lang.System.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int n = sc.nextInt();
		int[] ar = new int[n];
		for (int i=0; i<n; i++) {
			ar[i] = Integer.parseInt(sc.next());
		}
		Arrays.sort(ar);
		long a = 0;
		if (n%2==0) {a = (ar[n/2]+ar[(n-1)/2])/2;}
		else {a = ar[n/2];}
		long ans = 0;
		for (int i=0; i<n; i++) {
			ans += Math.abs(ar[i]-a);
		}
		out.println(ans);
	}
}
0