結果

問題 No.198 キャンディー・ボックス2
コンテスト
ユーザー yoma
提出日時 2020-02-19 16:04:39
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 496 bytes
コンパイル時間 1,317 ms
コンパイル使用メモリ 168,552 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-11-26 11:43:40
合計ジャッジ時間 2,356 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
using namespace::std;
typedef long long LL;
typedef pair<int, int> PI;
typedef pair<LL, LL> PL;

int main(){
    LL B, N;
    cin >> B >> N;
    vector<LL> c(N);
    LL csum = 0;
    for(int i = 0;i < N;i++)    {
        cin >> c[i];
        csum += c[i];
    }
    sort(c.begin(), c.end());
    int mid = max((int)(N-1)/2, 0);
    LL ans = 0;
    LL cm = min((csum+B)/N, c[mid]);
    for(int i = 0;i < N;i++){
        ans += abs(c[i]-cm);
    }
    cout << ans << endl;
}
0