結果

問題 No.198 キャンディー・ボックス2
ユーザー kuramukuramu
提出日時 2016-02-11 17:20:20
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 801 bytes
コンパイル時間 2,273 ms
コンパイル使用メモリ 74,552 KB
実行使用メモリ 53,544 KB
最終ジャッジ日時 2023-10-21 23:23:00
合計ジャッジ時間 5,652 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
53,528 KB
testcase_01 AC 56 ms
53,524 KB
testcase_02 AC 56 ms
53,512 KB
testcase_03 AC 56 ms
53,524 KB
testcase_04 AC 56 ms
53,520 KB
testcase_05 AC 56 ms
53,524 KB
testcase_06 AC 56 ms
52,408 KB
testcase_07 AC 57 ms
53,524 KB
testcase_08 AC 56 ms
53,512 KB
testcase_09 AC 56 ms
53,520 KB
testcase_10 AC 56 ms
53,512 KB
testcase_11 AC 57 ms
53,512 KB
testcase_12 AC 56 ms
53,524 KB
testcase_13 AC 55 ms
53,524 KB
testcase_14 AC 57 ms
53,520 KB
testcase_15 AC 58 ms
53,532 KB
testcase_16 AC 56 ms
53,524 KB
testcase_17 AC 57 ms
53,520 KB
testcase_18 AC 56 ms
53,512 KB
testcase_19 WA -
testcase_20 AC 56 ms
53,512 KB
testcase_21 WA -
testcase_22 AC 56 ms
53,516 KB
testcase_23 WA -
testcase_24 AC 56 ms
53,544 KB
testcase_25 WA -
testcase_26 AC 55 ms
53,524 KB
testcase_27 AC 55 ms
53,460 KB
testcase_28 WA -
testcase_29 AC 55 ms
53,524 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];
	    	  for(int i=0;i<N;i++){
	    		  num[i] = Integer.parseInt(stdReader.readLine());
	    	  }	    	  
	    	  Arrays.sort(num);
	    	  int center = num[(N-1)/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