結果

問題 No.198 キャンディー・ボックス2
ユーザー chiho_miyako
提出日時 2015-04-29 00:40:55
言語 Java
(openjdk 23)
結果
RE  
実行時間 -
コード長 813 bytes
コンパイル時間 1,951 ms
コンパイル使用メモリ 74,008 KB
実行使用メモリ 334,988 KB
最終ジャッジ日時 2024-07-05 09:16:33
合計ジャッジ時間 8,819 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 RE * 1
other AC * 9 RE * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner koko = new Scanner(System.in);
        long b = koko.nextLong();
        int n = koko.nextInt();
        long[] c = new long[n];
        long total=0;
        for(int i=0; i<n; i++){
        	c[i]=koko.nextInt();
        	total = total+c[i];
        }
        total = total + b;
        int max = (int)Math.floor(total/n);
        long[] move = new long[max+1];
        for(int i=0; i<max+1; i++){
        	move[i]=0;
        	for(int j=0; j<n; j++){
        	    move[i] = move[i]+Math.abs(c[j]-i);
            }
        }
        long movemin = move[0];
        for(int i=0; i<max+1; i++){
        	movemin = Math.min(movemin, move[i]);
        }
        System.out.println(movemin);
    }
}
0