結果
| 問題 | No.198 キャンディー・ボックス2 |
| コンテスト | |
| ユーザー |
bal4u
|
| 提出日時 | 2019-08-02 15:56:05 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 1,000 ms |
| コード長 | 746 bytes |
| コンパイル時間 | 261 ms |
| コンパイル使用メモリ | 26,288 KB |
| 実行使用メモリ | 7,720 KB |
| 最終ジャッジ日時 | 2025-11-26 11:43:14 |
| 合計ジャッジ時間 | 1,075 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 27 |
ソースコード
// yukicoder: No.198 キャンディー・ボックス2
// 2019.8.2 bal4u
#include <stdio.h>
#include <stdlib.h>
#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int in() { // 非負整数の入力
int n = 0, c = gc();
do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
return n;
}
#define ABS(x) ((x)>=0?(x):-(x))
int N;
int c[12];
int cmp(const void *a, const void *b) { return *(int *)a - *(int *)b; }
int main()
{
int B, i, a;
long long ans, s;
B = in(), N = in(), s = 0;
for (i = 0; i < N; i++) c[i] = in(), s += c[i];
qsort(c, N, sizeof(int), cmp);
a = c[N/2], ans = 0;
if ((long long)a*N > s+B) a = (s+B)/N;
for (i = 0; i < N; i++) ans += ABS(c[i]-a);
printf("%lld\n", ans);
return 0;
}
bal4u