結果

問題 No.198 キャンディー・ボックス2
ユーザー yoma
提出日時 2020-02-19 16:04:39
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 1,000 ms
コード長 496 bytes
コンパイル時間 1,710 ms
コンパイル使用メモリ 172,984 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-08 03:36:58
合計ジャッジ時間 2,823 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#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