結果

問題 No.198 キャンディー・ボックス2
コンテスト
ユーザー agatan
提出日時 2015-05-04 22:36:58
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 686 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 396 ms
コンパイル使用メモリ 90,732 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2026-03-27 04:27:24
合計ジャッジ時間 1,197 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 WA * 1
other AC * 10 WA * 17
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <cmath>

#define REP(i, n) for(int i=0;i<(n);i++)

using namespace std;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    long B, N;
    cin >> B >> N;
    vector<long> C;
    unsigned long sum = 0;

    REP(i,N) {
        long c;
        cin >> c;
        sum += c;
        C.push_back(c);
    }
    long ave = static_cast<long>(ceil((double)sum / N));
    long less = 0, more = 0;
    for(auto c: C) {
        if (c > ave) more += c - ave;
        else if (c < ave) less += ave - c;
    }
    if (less == more) {
        cout << less * 2 << endl;
    } else {
        cout << less + more << endl;
    }

    return 0;
}
0