結果

問題 No.31 悪のミックスジュース
ユーザー krotonkroton
提出日時 2014-10-19 07:15:47
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,433 bytes
コンパイル時間 676 ms
コンパイル使用メモリ 71,820 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-28 21:26:18
合計ジャッジ時間 1,988 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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);
    }*/
    
    ll res = S[N];
    
    V -= N;
    if(V > 0){
        res += V / opt * S[opt];
        res += dp[V % opt];
    }

    cout << res << endl;

    return 0;
}
0