結果

問題 No.198 キャンディー・ボックス2
ユーザー thorikawathorikawa
提出日時 2015-04-29 00:27:20
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 882 bytes
コンパイル時間 1,993 ms
コンパイル使用メモリ 72,904 KB
実行使用メモリ 56,168 KB
最終ジャッジ日時 2023-09-18 14:35:17
合計ジャッジ時間 7,133 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
55,860 KB
testcase_01 AC 128 ms
55,944 KB
testcase_02 AC 133 ms
55,944 KB
testcase_03 AC 126 ms
53,992 KB
testcase_04 AC 127 ms
55,796 KB
testcase_05 AC 125 ms
55,548 KB
testcase_06 AC 129 ms
55,700 KB
testcase_07 AC 129 ms
55,916 KB
testcase_08 AC 131 ms
55,696 KB
testcase_09 AC 129 ms
55,600 KB
testcase_10 AC 127 ms
55,820 KB
testcase_11 AC 127 ms
55,592 KB
testcase_12 AC 127 ms
55,736 KB
testcase_13 AC 128 ms
55,624 KB
testcase_14 AC 125 ms
55,944 KB
testcase_15 AC 126 ms
55,580 KB
testcase_16 AC 127 ms
55,928 KB
testcase_17 AC 128 ms
55,528 KB
testcase_18 AC 129 ms
55,996 KB
testcase_19 WA -
testcase_20 AC 128 ms
55,840 KB
testcase_21 WA -
testcase_22 AC 129 ms
55,884 KB
testcase_23 WA -
testcase_24 AC 127 ms
55,812 KB
testcase_25 WA -
testcase_26 AC 127 ms
55,816 KB
testcase_27 AC 127 ms
55,780 KB
testcase_28 WA -
testcase_29 AC 127 ms
55,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

/**
 * Created by poly on 11/29/14.
 */
public class Main {
    public static void main(String[] argv) {
        Scanner scanner = new Scanner(System.in);
        int b = scanner.nextInt();
        int n = scanner.nextInt();
        int[] c = new int[n];
        int total = 0;
        for (int i = 0; i < n; i++) {
            c[i] = scanner.nextInt();
            total += c[i];
        }
        total += b;
        int max = total / n;
        Arrays.sort(c);
        long ans = 0;
        for (int j = 0; j < n; j++) {
            ans += Math.abs(c[j] - max);
        }
        for (int i = 0; i < n; i++) {
            long tmp = 0;
            for (int j = 0; j < n; j++) {
                tmp += Math.abs(c[j] - c[i]);
            }
            ans = Math.min(tmp, ans);
        }
        System.out.println(ans);
    }
}
0