結果

問題 No.609 Noelちゃんと星々
ユーザー Daigo HIROOKADaigo HIROOKA
提出日時 2018-06-14 01:31:02
言語 Java21
(openjdk 21)
結果
AC  
実行時間 643 ms / 2,000 ms
コード長 553 bytes
コンパイル時間 3,088 ms
コンパイル使用メモリ 72,260 KB
実行使用メモリ 62,780 KB
最終ジャッジ日時 2023-09-13 04:04:31
合計ジャッジ時間 18,539 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 553 ms
60,472 KB
testcase_01 AC 439 ms
60,644 KB
testcase_02 AC 372 ms
58,752 KB
testcase_03 AC 422 ms
61,104 KB
testcase_04 AC 325 ms
61,024 KB
testcase_05 AC 583 ms
61,984 KB
testcase_06 AC 603 ms
60,464 KB
testcase_07 AC 531 ms
61,044 KB
testcase_08 AC 283 ms
61,012 KB
testcase_09 AC 425 ms
60,836 KB
testcase_10 AC 538 ms
60,960 KB
testcase_11 AC 512 ms
60,772 KB
testcase_12 AC 535 ms
60,392 KB
testcase_13 AC 297 ms
60,804 KB
testcase_14 AC 235 ms
60,148 KB
testcase_15 AC 565 ms
60,712 KB
testcase_16 AC 634 ms
61,724 KB
testcase_17 AC 544 ms
60,800 KB
testcase_18 AC 395 ms
60,684 KB
testcase_19 AC 558 ms
60,532 KB
testcase_20 AC 607 ms
62,780 KB
testcase_21 AC 643 ms
62,304 KB
testcase_22 AC 598 ms
62,360 KB
testcase_23 AC 639 ms
62,444 KB
testcase_24 AC 605 ms
60,016 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class No609{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		long[] Y = new long[N];
		for(int i = 0; i < N; i++){
			Y[i] = sc.nextLong();
		}
		Arrays.sort(Y);

		long med;
		if(N%2 != 0){
			med = Y[(N-1)/2];
		}else{
			long med_tmp = Y[N/2-1] + Y[N/2];
			if(med_tmp%2 > 0){
				med = med_tmp/2 + 1;
			}else{
				med = med_tmp/2;
			}
		}

		long diff = 0;
		for(int i = 0; i < N; i++){
			diff += Math.abs(med - Y[i]);
		}
		
		System.out.println(diff);
	}
}
0