結果

問題 No.198 キャンディー・ボックス2
ユーザー dazy
提出日時 2018-07-03 19:11:33
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 584 bytes
コンパイル時間 1,724 ms
コンパイル使用メモリ 172,876 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-01 01:59:45
合計ジャッジ時間 2,892 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 21 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define fastcin {\
    cin.tie(0);\
    ios::sync_with_stdio(false);\
}
#define rep(i, a, b) for(int i = a; i < b; i++)
#define print(x) cout << x << "\n"
#define VSORT(v) sort(v.begin(), v.end());
typedef long long ll;
typedef vector<ll> vll;

int main() {
    fastcin;
    ll b, n, in, mid, ans = 0;
    cin >> b >> n;
    vll c;
    rep(i, 0, n) {
        cin >> in;
        c.push_back(in);
    }
    VSORT(c);
    mid = c[n/2];
    rep(i, 0, n/2) ans += mid-c[i];
    rep(i, n/2+1, n) ans += c[i]-mid;
    print(ans);
    return 0;
}
0