結果

問題 No.31 悪のミックスジュース
ユーザー PachicobuePachicobue
提出日時 2017-07-03 17:52:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,482 bytes
コンパイル時間 1,920 ms
コンパイル使用メモリ 170,908 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-15 14:39:33
合計ジャッジ時間 2,574 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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<long double, int>> newcost(N);
    for (int i = 0; i < N; i++) {
        if (i == 0) {
            sum[i] = cost[i];
        } else {
            sum[i] = sum[i - 1] + cost[i];
        }
        newcost[i] = make_pair((long 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