結果
| 問題 |
No.198 キャンディー・ボックス2
|
| コンテスト | |
| ユーザー |
airuai
|
| 提出日時 | 2016-09-18 19:53:43 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 836 bytes |
| コンパイル時間 | 1,000 ms |
| コンパイル使用メモリ | 66,136 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-11-17 08:56:04 |
| 合計ジャッジ時間 | 1,788 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 WA * 1 |
| other | AC * 23 WA * 3 |
コンパイルメッセージ
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;
int 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 << "1" << 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