結果

問題 No.198 キャンディー・ボックス2
ユーザー aaaaaaiu
提出日時 2019-08-08 23:01:50
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 334 bytes
コンパイル時間 1,928 ms
コンパイル使用メモリ 194,980 KB
最終ジャッジ日時 2025-01-07 11:01:57
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 12 WA * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    int b, n;
    cin>>b>>n;
    int a[n];
    for (int i=0;i<n;i++) {
        cin>>a[i];
        b+=a[i];
    }
    sort(a,a+n);
    int c=min(b/n,a[n/2]);
    int ans=0;
    for (int i=0;i<n;i++) ans+=abs(a[i]-c);
    cout<<ans<<endl;
    return 0;
}
0