結果

問題 No.31 悪のミックスジュース
ユーザー izuru_matsuuraizuru_matsuura
提出日時 2016-02-16 23:02:04
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,368 bytes
コンパイル時間 1,399 ms
コンパイル使用メモリ 163,720 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-22 06:04:05
合計ジャッジ時間 2,290 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 WA -
testcase_10 AC 2 ms
4,348 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

namespace {

    typedef double real;
    typedef long long ll;

    template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) {
        if (vs.empty()) return os << "[]";
        os << "[" << vs[0];
        for (int i = 1; i < vs.size(); i++) os << " " << vs[i];
        return os << "]";
    }

    int N;
    ll V;
    vector<ll> C;
    void input() {
        cin >> N >> V;
        C.resize(N);
        for (int i = 0; i < N; i++) cin >> C[i];
    }

    void solve() {
        vector<ll> S(N, 0); // [0, k]を1[L]ずつまぜたジュースのk+1[L]の値段
        S[0] = C[0];
        for (int i = 1; i < N; i++) {
            S[i] = S[i - 1] + C[i];
        }

        V -= N;

        int k = N - 1;
        for (int i = 0; i < N; i++) {
            real c = real(S[i]) / (i + 1);
            if (c < real(S[k]) / (k + 1)) {
                k = i;
            }
        }

        if (V <= 0) {
            cout << S[N - 1] << endl;
            return;
        }

        ll ans = 1LL<<56;
        ans = min(ans, S[k] * (V + k) / (k + 1));
        for (int i = 0; i < N; i++) {
            ll v = V - (i + 1);
            ans = min(ans, S[i] + max(0LL, S[k] * ((v + k) / (k + 1))));
        }

        cout << ans + S[N - 1] << endl;
    }
}

int main() {
    input(); solve();
    return 0;
}

0