結果
| 問題 | No.31 悪のミックスジュース | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2014-10-19 07:13:10 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 7 ms / 5,000 ms | 
| コード長 | 1,298 bytes | 
| コンパイル時間 | 559 ms | 
| コンパイル使用メモリ | 71,144 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-09-14 15:50:28 | 
| 合計ジャッジ時間 | 1,300 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 17 | 
ソースコード
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <fstream>
#include <sstream>
using namespace std;
typedef long long ll;
const ll INF = 1ll << 60;
const int dp_size = 20000;
int N, V;
int C[110];
ll S[110];
ll dp[dp_size];
int main(){
    cin >> N >> V;
    for(int i=0;i<N;i++)cin >> C[i];
    
    S[0] = 0;
    for(int i=0;i<N;i++)S[i+1] = S[i] + C[i];
    for(int i=0;i<dp_size;i++){
        dp[i] = INF;
    }
    
    dp[0] = 0;
    for(int sum=0;sum<dp_size;sum++){
        for(int i=1;i<=N;i++){
            if(i <= sum)dp[sum] = min(dp[sum], dp[sum - i] + S[i]);
        }
    }
    
    int opt = 1;
    for(int i=2;i<=N;i++){
        if(S[i] * opt < S[opt] * i){
            opt = i;
        }
    }
 
    ll res = INF;
    for(int i=0;i<dp_size;i++){
        ll tmp = 0;
        int v = V;
        
        v -= N;
        tmp += S[N];
        
        v -= i;
        tmp += dp[i];
        
        if(v <= 0){
            res = min(res, tmp);
            continue;
        }
        
        tmp += (v + opt - 1) / opt * S[opt];
        res = min(res, tmp);
    }
    cout << res << endl;
    return 0;
}
            
            
            
        