結果

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

ソースコード

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++){
        long long 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);
    vector<long long> dp(N*N+1,1e18);
    dp.at(0) = 0;
    for(auto [c,v] : C) for(int i=0; i<=N*N-v; i++) dp.at(i+v) = min(dp.at(i+v),dp.at(i)+c);
    
    long long add = 1e18;
    for(int i=V%v0; i<=N*N; i+=v0){
        long long now = (V-i)/v0*c0;
        now += dp.at(i);
        add = min(add,now);
    }
    answer += add;
    cout << answer << endl;

}   
0