結果

問題 No.198 キャンディー・ボックス2
ユーザー haruki_57
提出日時 2015-05-04 01:19:40
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 730 bytes
コンパイル時間 1,902 ms
コンパイル使用メモリ 73,908 KB
実行使用メモリ 55,860 KB
最終ジャッジ日時 2024-07-05 18:43:04
合計ジャッジ時間 6,660 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 22 WA * 4
権限があれば一括ダウンロードができます

ソースコード

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