結果

問題 No.198 キャンディー・ボックス2
ユーザー haruki_57haruki_57
提出日時 2015-05-04 01:30:24
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 864 bytes
コンパイル時間 2,281 ms
コンパイル使用メモリ 72,140 KB
実行使用メモリ 58,008 KB
最終ジャッジ日時 2023-09-19 06:31:18
合計ジャッジ時間 7,958 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 145 ms
55,836 KB
testcase_10 AC 137 ms
55,828 KB
testcase_11 AC 140 ms
55,976 KB
testcase_12 AC 143 ms
55,756 KB
testcase_13 WA -
testcase_14 AC 135 ms
55,828 KB
testcase_15 AC 133 ms
55,772 KB
testcase_16 AC 133 ms
55,880 KB
testcase_17 AC 137 ms
56,160 KB
testcase_18 AC 142 ms
55,772 KB
testcase_19 AC 141 ms
56,004 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

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

}
0