結果
| 問題 | 
                            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 | 
| コンパイル時間 | 1,236 ms | 
| コンパイル使用メモリ | 96,104 KB | 
| 最終ジャッジ日時 | 2025-01-09 17:42:28 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 26 | 
ソースコード
#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;
}