結果
| 問題 | 
                            No.198 キャンディー・ボックス2
                             | 
                    
| コンテスト | |
| ユーザー | 
                             ngtkana
                         | 
                    
| 提出日時 | 2020-03-23 12:46:52 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 3 ms / 1,000 ms | 
| コード長 | 556 bytes | 
| コンパイル時間 | 2,920 ms | 
| コンパイル使用メモリ | 197,612 KB | 
| 最終ジャッジ日時 | 2025-01-09 09:45:39 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 26 | 
ソースコード
#include<bits/stdc++.h>
using lint=long long;
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint X,n;std::cin>>X>>n;
    std::vector<lint>a(n);
    for(lint&x:a)std::cin>>x;
    std::sort(a.begin(),a.end());
    lint sum=std::accumulate(a.begin(),a.end(),0ll);
    lint med=a.at(n/2);
    if(sum+X<med*n){
        med=(sum+X)/n;
    }
    std::cout<<std::accumulate(
        a.begin(),a.end(),0ll,[med](lint x,lint y){return x+std::abs(y-med);})<<'\n';
}
            
            
            
        
            
ngtkana