結果

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

ソースコード

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