結果

問題 No.198 キャンディー・ボックス2
ユーザー haruki_57haruki_57
提出日時 2015-05-04 01:12:50
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 759 bytes
コンパイル時間 2,489 ms
コンパイル使用メモリ 72,484 KB
実行使用メモリ 57,944 KB
最終ジャッジ日時 2023-09-19 06:30:37
合計ジャッジ時間 8,803 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 138 ms
55,556 KB
testcase_01 AC 136 ms
55,324 KB
testcase_02 AC 133 ms
55,752 KB
testcase_03 AC 132 ms
55,336 KB
testcase_04 AC 133 ms
55,740 KB
testcase_05 AC 135 ms
55,556 KB
testcase_06 AC 135 ms
55,712 KB
testcase_07 AC 133 ms
55,500 KB
testcase_08 AC 134 ms
55,612 KB
testcase_09 AC 133 ms
55,512 KB
testcase_10 AC 133 ms
55,752 KB
testcase_11 AC 130 ms
55,328 KB
testcase_12 AC 132 ms
55,604 KB
testcase_13 WA -
testcase_14 AC 134 ms
55,332 KB
testcase_15 AC 130 ms
55,860 KB
testcase_16 AC 130 ms
55,612 KB
testcase_17 AC 131 ms
55,488 KB
testcase_18 AC 135 ms
55,556 KB
testcase_19 WA -
testcase_20 AC 133 ms
55,592 KB
testcase_21 WA -
testcase_22 AC 132 ms
55,336 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 134 ms
55,696 KB
testcase_27 AC 133 ms
55,484 KB
testcase_28 WA -
testcase_29 AC 134 ms
55,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.math.BigInteger;
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