結果

問題 No.31 悪のミックスジュース
ユーザー t98slidert98slider
提出日時 2022-05-10 04:26:37
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 830 bytes
コンパイル時間 1,733 ms
コンパイル使用メモリ 174,532 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-24 08:39:22
合計ジャッジ時間 2,875 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;

int main(){
    ll n, v, sumv = 0;
    cin >> n >> v;
    vector<ll> a(n);
    vector<pair<ll,ll>> b(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        sumv += a[i];
        b[i]={sumv, i + 1};
    }
    sort(b.begin(),b.end(),[&](pair<ll,ll> l, pair<ll,ll> r){
        return l.first * r.second < r.first * l.second;
    });
    ll ans = sumv, d;
    v -= min(v, n);
    d = max(0ll, (v - 10000) / b[0].second);
    v -= d * b[0].second;
    ans += d * b[0].first;
    vector<ll> dp(v + 1, 1ll << 62);
    dp[0] = 0;
    for(int i = 0; i < n; i++){
        ll c, sv;
        tie(c, sv) = b[i];
        for(int j = 0; j + sv <= v; j++){
            dp[j + sv] = min(dp[j + sv], dp[j] + c);
        }
    }
    ans += dp[v];
    cout << ans << endl;
}
0