結果

問題 No.31 悪のミックスジュース
ユーザー GOTKAKO
提出日時 2025-05-22 17:25:54
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 798 bytes
コンパイル時間 2,049 ms
コンパイル使用メモリ 203,780 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-05-22 17:25:58
合計ジャッジ時間 3,282 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 8 WA * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int N,V; cin >> N >> V;
    long long answer = 0;
    vector<pair<long long,long long>> C(N);
    for(int i=0; i<N; i++){
        int c; cin >> c; answer += c;
        C.at(i) = {c,i+1};
    }
    V -= N;
    if(V <= 0){cout << answer << endl; return 0;}
    for(int i=1; i<N; i++) C.at(i).first += C.at(i-1).first;
    sort(C.begin(),C.end(),[&](auto &a,auto &b){return a.first*b.second < b.first*a.second;});

    auto [c0,v0] = C.at(0);
    answer += V/v0*c0; V %= v0;
    vector<long long> dp(V+1,1e18);
    dp.at(0) = 0;
    for(auto [c,v] : C) for(int i=0; i<=V-v; i++) dp.at(i+v) = min(dp.at(i+v),dp.at(i)+c);
    answer += dp.back();
    cout << answer << endl;
}   
0