結果

問題 No.198 キャンディー・ボックス2
ユーザー kura197kura197
提出日時 2019-11-09 00:40:02
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,289 bytes
コンパイル時間 1,394 ms
コンパイル使用メモリ 144,112 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-13 06:08:39
合計ジャッジ時間 2,497 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,356 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 2 ms
4,356 KB
testcase_09 AC 2 ms
4,352 KB
testcase_10 AC 1 ms
4,352 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 1 ms
4,356 KB
testcase_13 AC 1 ms
4,352 KB
testcase_14 AC 1 ms
4,352 KB
testcase_15 AC 1 ms
4,356 KB
testcase_16 AC 1 ms
4,352 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 1 ms
4,352 KB
testcase_19 AC 2 ms
4,352 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 1 ms
4,352 KB
testcase_22 AC 1 ms
4,352 KB
testcase_23 AC 1 ms
4,372 KB
testcase_24 AC 2 ms
4,352 KB
testcase_25 AC 2 ms
4,352 KB
testcase_26 AC 1 ms
4,348 KB
testcase_27 AC 2 ms
4,352 KB
testcase_28 AC 1 ms
4,352 KB
testcase_29 AC 2 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;
const ll INF = 1e11;

ll B;
ll N;
ll C[20];

ll solve(ll x){
    ll score = 0;
    ll b = B;
    REP(i,N){
        ll c = C[i];
        if(c - x > 0){
            b += c-x;
            score += c-x;
        }
    }

    REP(i,N){
        ll c = C[i];
        if(x - c > 0){
            b -= x-c;
            score += x-c;
        }
    }

    if(b < 0) score += INF;
    return score;
}

int main(){
    cin >> B;
    cin >> N;
    REP(i,N){
        ll c;
        cin >> c;
        C[i] = c;
    }

    ll left = 0;
    ll right = 1e10;
    ll ans = 0;
    REP(i,100){
        ll x1 = (left*2 + right) / 3;
        ll x2 = (left + right*2) / 3;
        ll s1 = solve(x1);
        ll s2 = solve(x2);
        if(s1 < s2){
            right = x2;
            ans = s1;
        }
        else{
            left = x1;
            ans = s2;
        }
    }

    cout << ans << endl;
    return 0;
}
0