結果
問題 | No.198 キャンディー・ボックス2 |
ユーザー |
![]() |
提出日時 | 2020-11-17 21:26:09 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 138 ms / 1,000 ms |
コード長 | 579 bytes |
コンパイル時間 | 2,241 ms |
コンパイル使用メモリ | 74,356 KB |
実行使用メモリ | 54,588 KB |
最終ジャッジ日時 | 2024-07-23 08:29:30 |
合計ジャッジ時間 | 7,578 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 26 |
ソースコード
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int b = sc.nextInt(); int n = sc.nextInt(); int[] arr = new int[n]; long sum = b; for (int i = 0; i < n; i++) { arr[i] = sc.nextInt(); sum += arr[i]; } Arrays.sort(arr); long count = Math.min(arr[(n - 1) / 2], sum / n); long ans = 0; for (int x : arr) { ans += Math.abs(count - x); } System.out.println(ans); } }