結果

問題 No.31 悪のミックスジュース
ユーザー Pachicobue
提出日時 2017-07-03 17:49:00
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,524 bytes
コンパイル時間 1,856 ms
コンパイル使用メモリ 175,628 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-05 12:29:12
合計ジャッジ時間 2,059 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 8 WA * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define show(x) cout << #x << " = " << x << endl

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz=" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
    os << "(" << p.first << "," << p.second
       << ")";
    return os;
}


constexpr ll MOD = 1e9 + 7;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 100;

int main()
{
    int N;
    ll V;
    cin >> N >> V;
    vector<ll> cost(N);
    ll suma = 0;
    for (int i = 0; i < N; i++) {
        cin >> cost[i];
        suma += cost[i];
    }
    if (V <= N) {
        cout << suma << endl;
        return 0;
    }
    V -= N;
    vector<ll> sum(N);
    vector<pair<double, int>> newcost(N);
    for (int i = 0; i < N; i++) {
        if (i == 0) {
            sum[i] = cost[i];
            newcost[i] = make_pair(cost[i], i);
        } else {
            sum[i] = sum[i - 1] + cost[i];
            newcost[i] = make_pair((double)sum[i] / (i + 1), i);
        }
    }
    sort(newcost.begin(), newcost.end());
    for (int i = 0; i < N; i++) {
        const int ind = newcost[i].second;
        const ll vol = V / (ind + 1);
        suma += vol * sum[ind];
        V = V % (ind + 1);
    }
    cout << suma << endl;

    return 0;
}
0