結果

問題 No.31 悪のミックスジュース
ユーザー krotonkroton
提出日時 2014-10-19 07:13:10
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 1,298 bytes
コンパイル時間 534 ms
コンパイル使用メモリ 72,356 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-12 17:15:11
合計ジャッジ時間 1,497 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#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;
}
0