結果

問題 No.609 Noelちゃんと星々
ユーザー YamaKasa
提出日時 2018-09-28 13:25:25
言語 Java
(openjdk 23)
結果
AC  
実行時間 670 ms / 2,000 ms
コード長 625 bytes
コンパイル時間 2,101 ms
コンパイル使用メモリ 74,872 KB
実行使用メモリ 60,828 KB
最終ジャッジ日時 2024-10-12 04:48:14
合計ジャッジ時間 17,115 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int[]Y = new int[N];
		for(int i = 0; i < N; i++) {
			Y[i] = scan.nextInt();
		}
		scan.close();
		Arrays.sort(Y);
		if(N % 2 == 0) {
			int t = (Y[N / 2] + Y[N /2 - 1]) / 2;
			long ans = 0;
			for(int i = 0; i < N; i++) {
				ans += Math.abs(t - Y[i]);
			}
			System.out.println(ans);
		}else {
			long ans = 0;
			int t = Y[N / 2];
			for(int i = 0; i < N; i++) {
				ans += Math.abs(t - Y[i]);
			}
			System.out.println(ans);
		}
	}
}
0