結果
| 問題 | No.198 キャンディー・ボックス2 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-04-12 15:04:57 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 1,000 ms |
| コード長 | 641 bytes |
| コンパイル時間 | 766 ms |
| コンパイル使用メモリ | 97,892 KB |
| 実行使用メモリ | 7,840 KB |
| 最終ジャッジ日時 | 2025-11-26 11:44:00 |
| 合計ジャッジ時間 | 1,775 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 27 |
ソースコード
#include <iostream>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <vector>
using lint = long long;
void solve() {
lint b;
std::cin >> b;
int n;
std::cin >> n;
std::vector<lint> xs(n);
for (auto& x : xs) std::cin >> x;
std::sort(xs.begin(), xs.end());
auto g = std::min(xs[n / 2],
(std::accumulate(xs.begin(), xs.end(), 0LL) + b) / n);
lint ans = 0;
for (auto x : xs) {
ans += std::abs(x - g);
}
std::cout << ans << std::endl;
}
int main() {
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
solve();
return 0;
}