結果
| 問題 |
No.198 キャンディー・ボックス2
|
| コンテスト | |
| ユーザー |
airuai
|
| 提出日時 | 2016-09-18 20:09:17 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 842 bytes |
| コンパイル時間 | 610 ms |
| コンパイル使用メモリ | 65,884 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-17 09:02:21 |
| 合計ジャッジ時間 | 1,529 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 25 WA * 1 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:41:20: warning: ‘lv’ may be used uninitialized in this function [-Wmaybe-uninitialized]
41 | lv -= sa / n;
| ~~~^~~~~~~~~
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
int main() {
std::cin.tie(0);
std::ios::sync_with_stdio(false);
int b;
std::cin >> b;
int n;
std::cin >> n;
long long sum = 0;
std::vector<int> c;
int a;
for (int i = 0; i < n; ++i) {
std::cin >> a;
c.push_back(a);
sum += a;
}
std::sort(c.begin(), c.end());
if (n == 1) {
std::cout << "0" << std::endl;
return 0;
}
long long count = 0, t = 20000000000;
int lv, i;
for (i = 0; i < n; ++i, t = count, count = 0) {
for (int j = 0; j < n; ++j) {
count += abs(c[i] - c[j]);
}
if (count >= t) {
lv = c[i-1];
break;
}
}
if (i > n) {
lv = c[n - 1];
}
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