結果

問題 No.198 キャンディー・ボックス2
ユーザー kenji_shioyakenji_shioya
提出日時 2016-06-16 06:14:30
言語 Java21
(openjdk 21)
結果
AC  
実行時間 123 ms / 1,000 ms
コード長 699 bytes
コンパイル時間 3,589 ms
コンパイル使用メモリ 74,968 KB
実行使用メモリ 54,280 KB
最終ジャッジ日時 2024-04-28 01:56:02
合計ジャッジ時間 6,701 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 107 ms
54,172 KB
testcase_01 AC 104 ms
54,212 KB
testcase_02 AC 106 ms
54,028 KB
testcase_03 AC 104 ms
53,864 KB
testcase_04 AC 100 ms
52,884 KB
testcase_05 AC 99 ms
53,044 KB
testcase_06 AC 96 ms
52,900 KB
testcase_07 AC 114 ms
54,180 KB
testcase_08 AC 118 ms
54,212 KB
testcase_09 AC 96 ms
52,592 KB
testcase_10 AC 102 ms
53,540 KB
testcase_11 AC 109 ms
54,080 KB
testcase_12 AC 111 ms
54,224 KB
testcase_13 AC 106 ms
53,040 KB
testcase_14 AC 113 ms
54,164 KB
testcase_15 AC 111 ms
53,756 KB
testcase_16 AC 97 ms
52,484 KB
testcase_17 AC 107 ms
53,700 KB
testcase_18 AC 104 ms
53,812 KB
testcase_19 AC 93 ms
52,472 KB
testcase_20 AC 104 ms
53,796 KB
testcase_21 AC 108 ms
53,936 KB
testcase_22 AC 111 ms
54,204 KB
testcase_23 AC 112 ms
53,776 KB
testcase_24 AC 106 ms
54,280 KB
testcase_25 AC 104 ms
53,808 KB
testcase_26 AC 102 ms
52,944 KB
testcase_27 AC 107 ms
54,096 KB
testcase_28 AC 94 ms
52,740 KB
testcase_29 AC 123 ms
53,860 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Exercise88{
  public static void main (String[] args){

    Scanner sc = new Scanner(System.in);

    long h = sc.nextInt();
    int n = sc.nextInt();
    long[] box = new long[n];
    long sum = 0;
    long ave = 0;

    for(int i = 0; i < n; i++){
      box[i] = sc.nextInt();
      sum += box[i];
    }
    sum += h;
    Arrays.sort(box);
    ave = sum / (long)n;
    ave = Math.min(sum / n, box[n / 2]);
    long answer = 0;
    for(int i = 0; i < box.length; i++){
      long x = box[i] - ave;
      if(x == 0){
        continue;
      }else if(x < 0){
      answer += x * -1;
      }else{
      answer += x;
      }
    }
    System.out.println(answer);
  }
}
0