結果

問題 No.198 キャンディー・ボックス2
ユーザー kuramukuramu
提出日時 2016-02-11 19:15:12
言語 Java21
(openjdk 21)
結果
AC  
実行時間 46 ms / 1,000 ms
コード長 859 bytes
コンパイル時間 2,269 ms
コンパイル使用メモリ 75,356 KB
実行使用メモリ 37,360 KB
最終ジャッジ日時 2024-04-28 01:44:46
合計ジャッジ時間 3,978 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
36,852 KB
testcase_01 AC 45 ms
36,884 KB
testcase_02 AC 44 ms
37,276 KB
testcase_03 AC 45 ms
37,284 KB
testcase_04 AC 44 ms
36,900 KB
testcase_05 AC 43 ms
37,168 KB
testcase_06 AC 42 ms
36,864 KB
testcase_07 AC 44 ms
37,308 KB
testcase_08 AC 44 ms
37,356 KB
testcase_09 AC 43 ms
37,280 KB
testcase_10 AC 43 ms
37,120 KB
testcase_11 AC 42 ms
37,276 KB
testcase_12 AC 45 ms
37,116 KB
testcase_13 AC 43 ms
37,200 KB
testcase_14 AC 44 ms
37,240 KB
testcase_15 AC 44 ms
37,116 KB
testcase_16 AC 44 ms
37,036 KB
testcase_17 AC 44 ms
37,280 KB
testcase_18 AC 43 ms
37,356 KB
testcase_19 AC 45 ms
37,356 KB
testcase_20 AC 45 ms
37,276 KB
testcase_21 AC 45 ms
37,164 KB
testcase_22 AC 43 ms
36,888 KB
testcase_23 AC 44 ms
37,280 KB
testcase_24 AC 44 ms
37,276 KB
testcase_25 AC 45 ms
37,028 KB
testcase_26 AC 46 ms
37,252 KB
testcase_27 AC 45 ms
36,888 KB
testcase_28 AC 44 ms
36,772 KB
testcase_29 AC 45 ms
37,360 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	 public static void main(String[] args) {
	      BufferedReader stdReader =new BufferedReader(new InputStreamReader(System.in));
	      try {
	    	  int B = Integer.parseInt(stdReader.readLine());
	    	  int N = Integer.parseInt(stdReader.readLine());
	    	  int[] num = new int[N];
	    	  long sum = B;
	    	  for(int i=0;i<N;i++){
	    		  num[i] = Integer.parseInt(stdReader.readLine());
	    		  sum += num[i];
	    	  }	    	  
	    	  Arrays.sort(num);
	    	  long center = Math.min(sum/N,num[N/2]);
	    	  long ans = 0;
	    	  for(int i=0;i<N;i++){
	    		  ans += Math.abs(num[i]-center);
	    	  }
	    	  System.out.println(ans);
	      } catch (IOException e) {
			e.printStackTrace();
	      }
	}
}
0