結果

問題 No.198 キャンディー・ボックス2
ユーザー h_nosonh_noson
提出日時 2016-02-26 10:22:37
言語 C++11
(gcc 11.4.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 793 bytes
コンパイル時間 342 ms
コンパイル使用メモリ 54,980 KB
最終ジャッジ日時 2024-04-27 02:17:45
合計ジャッジ時間 802 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:30:14: error: ‘accumulate’ was not declared in this scope
   30 |     r = min((accumulate(c,c+n,0LL) + b) / n,*max_element(c,c+n));
      |              ^~~~~~~~~~

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

#define RREP(i,s,e) for (i = e-1; i >= s; i--)
#define rrep(i,n) RREP(i,0,n)
#define REP(i,s,e) for (i = s; i < e; i++)
#define rep(i,n) REP(i,0,n)
#define INF 1e8

typedef long long ll;

ll c[10];
int n;

ll cost (int h) {
    int i;
    ll ret = 0;
    rep (i,n) ret += abs(c[i] - h);
    return ret;
}

int main() {
    int i;
    ll b, l, r;
    cin >> b >> n;
    rep (i,n) cin >> c[i];
    l = *min_element(c,c+n);
    r = min((accumulate(c,c+n,0LL) + b) / n,*max_element(c,c+n));
    while (l < r) {
        int m = (l + r) / 2;
        ll c1 = cost(m);
        ll c2 = cost(m+1);
        if (c1 < c2)
            r = m;
        else
            l = m+1;
    }
    cout << cost(l) << endl;
    return 0;
}
0