結果

問題 No.198 キャンディー・ボックス2
コンテスト
ユーザー ぴろず
提出日時 2015-04-28 23:31:19
言語 Java
(openjdk 23)
結果
AC  
実行時間 128 ms / 1,000 ms
コード長 515 bytes
コンパイル時間 2,241 ms
コンパイル使用メモリ 82,848 KB
実行使用メモリ 46,836 KB
最終ジャッジ日時 2025-11-26 11:33:31
合計ジャッジ時間 6,716 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

package no198;

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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int b = sc.nextInt();
		int n = sc.nextInt();
		long sum = b;
		int[] c = new int[n];
		for(int i=0;i<n;i++) {
			c[i] = sc.nextInt();
			sum += c[i];
		}
		Arrays.sort(c);
		long x = c[(n-1)/2];
		if (x * n > sum) {
			x = sum / n;
		}
		long ans = 0;
		for(int i=0;i<n;i++) {
			ans += Math.abs(c[i] - x);
		}
		System.out.println(ans);
	}
}
0