結果
問題 | No.198 キャンディー・ボックス2 |
ユーザー |
![]() |
提出日時 | 2015-04-28 23:31:19 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 136 ms / 1,000 ms |
コード長 | 515 bytes |
コンパイル時間 | 2,442 ms |
コンパイル使用メモリ | 75,020 KB |
実行使用メモリ | 41,412 KB |
最終ジャッジ日時 | 2024-11-16 08:56:13 |
合計ジャッジ時間 | 7,685 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 26 |
ソースコード
package no198; import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int b = sc.nextInt(); int n = sc.nextInt(); long sum = b; int[] c = new int[n]; for(int i=0;i<n;i++) { c[i] = sc.nextInt(); sum += c[i]; } Arrays.sort(c); long x = c[(n-1)/2]; if (x * n > sum) { x = sum / n; } long ans = 0; for(int i=0;i<n;i++) { ans += Math.abs(c[i] - x); } System.out.println(ans); } }