結果

問題 No.198 キャンディー・ボックス2
ユーザー ぴろずぴろず
提出日時 2015-04-28 23:31:19
言語 Java19
(openjdk 21)
結果
AC  
実行時間 130 ms / 1,000 ms
コード長 515 bytes
コンパイル時間 3,900 ms
コンパイル使用メモリ 71,892 KB
実行使用メモリ 56,484 KB
最終ジャッジ日時 2023-08-10 07:25:43
合計ジャッジ時間 7,043 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
56,484 KB
testcase_01 AC 126 ms
55,712 KB
testcase_02 AC 126 ms
55,952 KB
testcase_03 AC 124 ms
55,944 KB
testcase_04 AC 122 ms
55,940 KB
testcase_05 AC 123 ms
56,172 KB
testcase_06 AC 123 ms
55,768 KB
testcase_07 AC 124 ms
56,296 KB
testcase_08 AC 124 ms
54,396 KB
testcase_09 AC 123 ms
56,008 KB
testcase_10 AC 123 ms
55,752 KB
testcase_11 AC 120 ms
55,520 KB
testcase_12 AC 121 ms
56,140 KB
testcase_13 AC 124 ms
56,300 KB
testcase_14 AC 123 ms
56,140 KB
testcase_15 AC 122 ms
56,368 KB
testcase_16 AC 122 ms
55,892 KB
testcase_17 AC 122 ms
55,820 KB
testcase_18 AC 122 ms
55,524 KB
testcase_19 AC 123 ms
55,972 KB
testcase_20 AC 123 ms
56,048 KB
testcase_21 AC 125 ms
56,152 KB
testcase_22 AC 130 ms
56,060 KB
testcase_23 AC 125 ms
56,248 KB
testcase_24 AC 124 ms
55,820 KB
testcase_25 AC 126 ms
56,192 KB
testcase_26 AC 126 ms
55,792 KB
testcase_27 AC 125 ms
55,588 KB
testcase_28 AC 126 ms
55,980 KB
testcase_29 AC 123 ms
55,832 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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