結果

問題 No.198 キャンディー・ボックス2
ユーザー chiho_miyakochiho_miyako
提出日時 2015-04-29 00:40:55
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 813 bytes
コンパイル時間 2,370 ms
コンパイル使用メモリ 71,764 KB
実行使用メモリ 345,836 KB
最終ジャッジ日時 2023-09-18 19:37:34
合計ジャッジ時間 8,542 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 AC 122 ms
56,204 KB
testcase_10 AC 122 ms
57,388 KB
testcase_11 AC 121 ms
56,240 KB
testcase_12 RE -
testcase_13 RE -
testcase_14 AC 122 ms
55,888 KB
testcase_15 AC 122 ms
56,332 KB
testcase_16 AC 122 ms
56,208 KB
testcase_17 AC 121 ms
55,720 KB
testcase_18 AC 122 ms
55,660 KB
testcase_19 AC 125 ms
56,072 KB
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 AC 470 ms
216,612 KB
testcase_26 AC 553 ms
252,012 KB
testcase_27 AC 786 ms
345,836 KB
testcase_28 RE -
testcase_29 RE -
権限があれば一括ダウンロードができます

ソースコード

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