結果

問題 No.198 キャンディー・ボックス2
ユーザー haruki_57haruki_57
提出日時 2015-05-04 01:19:40
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 730 bytes
コンパイル時間 1,950 ms
コンパイル使用メモリ 74,852 KB
実行使用メモリ 56,212 KB
最終ジャッジ日時 2023-09-19 06:31:00
合計ジャッジ時間 7,483 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
55,800 KB
testcase_01 AC 125 ms
55,740 KB
testcase_02 AC 125 ms
55,732 KB
testcase_03 AC 123 ms
55,736 KB
testcase_04 AC 125 ms
55,688 KB
testcase_05 AC 125 ms
55,584 KB
testcase_06 AC 124 ms
55,548 KB
testcase_07 AC 122 ms
55,852 KB
testcase_08 AC 123 ms
55,636 KB
testcase_09 AC 124 ms
55,948 KB
testcase_10 AC 124 ms
56,060 KB
testcase_11 AC 124 ms
55,436 KB
testcase_12 AC 124 ms
55,544 KB
testcase_13 AC 126 ms
55,680 KB
testcase_14 AC 125 ms
55,680 KB
testcase_15 AC 124 ms
55,368 KB
testcase_16 AC 124 ms
55,736 KB
testcase_17 AC 128 ms
55,732 KB
testcase_18 AC 124 ms
55,900 KB
testcase_19 AC 127 ms
55,884 KB
testcase_20 AC 125 ms
55,368 KB
testcase_21 WA -
testcase_22 AC 125 ms
55,304 KB
testcase_23 WA -
testcase_24 AC 125 ms
55,744 KB
testcase_25 WA -
testcase_26 AC 127 ms
55,464 KB
testcase_27 AC 128 ms
55,664 KB
testcase_28 WA -
testcase_29 AC 129 ms
55,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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();
        int[] c = new int[n];
        for (int i = 0; i < c.length; i++) {
            c[i] = sc.nextInt();
        }
        long ans = Long.MAX_VALUE;
        for (int i = 0; i < c.length; i++) {
            int d = c[i];
            int bb = b;
            long cnt = 0;
            for (int j = 0; j < c.length; j++) {
                cnt += Math.abs(c[j]-d);
                bb -= d-c[j];
            }
            if(bb < 0)continue;
            ans = Math.min(ans, cnt);   
        }
        System.out.println(ans);
    }

}
0