結果

問題 No.198 キャンディー・ボックス2
ユーザー chiho_miyakochiho_miyako
提出日時 2015-04-29 00:05:21
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 797 bytes
コンパイル時間 2,031 ms
コンパイル使用メモリ 71,252 KB
実行使用メモリ 58,076 KB
最終ジャッジ日時 2023-09-18 14:29:42
合計ジャッジ時間 7,250 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
56,160 KB
testcase_01 AC 126 ms
56,068 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 123 ms
55,592 KB
testcase_10 AC 124 ms
55,832 KB
testcase_11 AC 126 ms
56,232 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 126 ms
55,544 KB
testcase_15 WA -
testcase_16 AC 129 ms
55,892 KB
testcase_17 WA -
testcase_18 AC 126 ms
55,776 KB
testcase_19 AC 125 ms
55,748 KB
testcase_20 AC 125 ms
55,648 KB
testcase_21 WA -
testcase_22 AC 124 ms
55,812 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 124 ms
55,756 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 124 ms
55,908 KB
権限があれば一括ダウンロードができます

ソースコード

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;
        long ave = Math.round(total/n);
        long move = 0;
        if(ave*n<=total+b){
        	for(int i=0; i<n; i++){
        	    move = move + Math.abs(c[i]-ave);
            }
            System.out.println(move);
        }else{
        	for(int i=0; i<n; i++){
        	    move = move + Math.abs(c[i]-ave+1);
            }
            System.out.println(move);
        }
        
    }
}
0