結果
| 問題 | No.198 キャンディー・ボックス2 |
| コンテスト | |
| ユーザー |
thorikawa
|
| 提出日時 | 2015-04-29 00:35:36 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 129 ms / 1,000 ms |
| コード長 | 934 bytes |
| コンパイル時間 | 2,613 ms |
| コンパイル使用メモリ | 77,268 KB |
| 実行使用メモリ | 46,912 KB |
| 最終ジャッジ日時 | 2025-11-26 11:34:29 |
| 合計ジャッジ時間 | 7,392 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 27 |
ソースコード
import java.util.Arrays;
import java.util.Scanner;
/**
* Created by poly on 11/29/14.
*/
public class Main {
public static void main(String[] argv) {
Scanner scanner = new Scanner(System.in);
int b = scanner.nextInt();
int n = scanner.nextInt();
long[] c = new long[n];
long total = b;
for (int i = 0; i < n; i++) {
c[i] = scanner.nextLong();
total += c[i];
}
long max = total / n;
Arrays.sort(c);
long ans = 0;
for (int j = 0; j < n; j++) {
ans += Math.abs(c[j] - max);
}
for (int i = 0; i < n; i++) {
if (c[i] > max) {
break;
}
long tmp = 0;
for (int j = 0; j < n; j++) {
tmp += Math.abs(c[j] - c[i]);
}
ans = Math.min(tmp, ans);
}
System.out.println(ans);
}
}
thorikawa