結果
| 問題 | No.198 キャンディー・ボックス2 |
| コンテスト | |
| ユーザー |
kenji_shioya
|
| 提出日時 | 2016-06-16 06:14:30 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 129 ms / 1,000 ms |
| コード長 | 699 bytes |
| コンパイル時間 | 3,619 ms |
| コンパイル使用メモリ | 83,068 KB |
| 実行使用メモリ | 46,796 KB |
| 最終ジャッジ日時 | 2025-11-26 11:39:51 |
| 合計ジャッジ時間 | 8,649 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 27 |
ソースコード
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);
}
}
kenji_shioya