結果
| 問題 |
No.198 キャンディー・ボックス2
|
| コンテスト | |
| ユーザー |
airuai
|
| 提出日時 | 2016-09-18 17:42:02 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 795 bytes |
| コンパイル時間 | 474 ms |
| コンパイル使用メモリ | 56,352 KB |
| 実行使用メモリ | 16,720 KB |
| 最終ジャッジ日時 | 2024-11-17 08:56:00 |
| 合計ジャッジ時間 | 35,547 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 WA * 1 |
| other | AC * 9 WA * 2 TLE * 15 |
ソースコード
#include <iostream>
int main() {
std::cin.tie(0);
std::ios::sync_with_stdio(false);
int b;
std::cin >> b;
int n;
std::cin >> n;
int sum = 0, *c, maxi = 0;
c = new int[n];
for (int i = 0; i < n; ++i) {
std::cin >> c[i];
sum += c[i];
if (maxi < c[i]) {
maxi = c[i];
}
}
if (n == 1) {
std::cout << "1" << std::endl;
return 0;
}
long long count = 0, t = 20000000000;
int lv, i;
for (i = 0; i <= maxi; ++i, t = count, count = 0) {
for (int j = 0; j < n; ++j) {
count += abs(i - c[j]);
}
if (count >= t) {
lv = i - 1;
break;
}
}
if (i > maxi) {
lv = maxi;
}
int sa;
if ((sa = lv * n - (sum + b)) > 0) {
lv -= sa / n;
lv -= ((sa % n) ? 1 : 0);
}
t = 0;
for (int i = 0; i < n; ++i) {
t += abs(lv - c[i]);
}
std::cout << t << std::endl;
}
airuai