結果

問題 No.198 キャンディー・ボックス2
ユーザー tentententen
提出日時 2020-11-17 21:26:09
言語 Java21
(openjdk 21)
結果
AC  
実行時間 132 ms / 1,000 ms
コード長 579 bytes
コンパイル時間 2,166 ms
コンパイル使用メモリ 71,968 KB
実行使用メモリ 56,352 KB
最終ジャッジ日時 2023-09-30 14:27:16
合計ジャッジ時間 7,843 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
55,860 KB
testcase_01 AC 131 ms
55,920 KB
testcase_02 AC 127 ms
55,788 KB
testcase_03 AC 125 ms
55,872 KB
testcase_04 AC 126 ms
55,952 KB
testcase_05 AC 128 ms
55,844 KB
testcase_06 AC 128 ms
55,856 KB
testcase_07 AC 128 ms
56,064 KB
testcase_08 AC 130 ms
56,108 KB
testcase_09 AC 127 ms
55,944 KB
testcase_10 AC 127 ms
55,580 KB
testcase_11 AC 126 ms
55,812 KB
testcase_12 AC 124 ms
55,856 KB
testcase_13 AC 128 ms
56,068 KB
testcase_14 AC 128 ms
55,864 KB
testcase_15 AC 126 ms
55,580 KB
testcase_16 AC 124 ms
55,868 KB
testcase_17 AC 126 ms
55,924 KB
testcase_18 AC 124 ms
55,816 KB
testcase_19 AC 125 ms
55,808 KB
testcase_20 AC 128 ms
55,944 KB
testcase_21 AC 131 ms
55,572 KB
testcase_22 AC 127 ms
55,792 KB
testcase_23 AC 126 ms
55,840 KB
testcase_24 AC 127 ms
56,224 KB
testcase_25 AC 131 ms
55,812 KB
testcase_26 AC 131 ms
56,352 KB
testcase_27 AC 132 ms
55,624 KB
testcase_28 AC 129 ms
55,564 KB
testcase_29 AC 128 ms
55,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

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