結果
| 問題 | No.31 悪のミックスジュース | 
| コンテスト | |
| ユーザー |  beet | 
| 提出日時 | 2018-11-07 17:39:55 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 1,269 ms / 5,000 ms | 
| コード長 | 974 bytes | 
| コンパイル時間 | 2,181 ms | 
| コンパイル使用メモリ | 199,108 KB | 
| 最終ジャッジ日時 | 2025-01-06 15:49:41 | 
| ジャッジサーバーID (参考情報) | judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 17 | 
ソースコード
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
//INSERT ABOVE HERE
signed main(){
  const Int MAX = 1e6;
  const Int INF = 2e18;
  Int n,v;
  cin>>n>>v;
  vector<Int> c(n);
  for(Int i=0;i<n;i++) cin>>c[i];
  
  using P = pair<Int, Int>;
  vector<P> vp;
  for(Int i=0,s=0;i<n;i++){
    s+=c[i];
    vp.emplace_back(i+1,s);
  }
  
  vector<Int> dp(MAX,INF);
  dp[0]=0;
  for(Int i=0;i<n;i++)
    for(Int j=0;j+vp[i].first<MAX;j++)
      chmin(dp[j+vp[i].first],dp[j]+vp[i].second);  
      
  v-=min(v,n);
  Int ans=INF;
  for(Int j=0;j<MAX;j++){
    if(j>=v){
      chmin(ans,dp[j]);
      continue;
    }
    for(Int i=0;i<n;i++){
      Int d=(v-j+vp[i].first-1)/vp[i].first;
      chmin(ans,dp[j]+d*vp[i].second);
    }
  }
  
  for(Int i=0;i<n;i++) ans+=c[i];
  cout<<ans<<endl;
  return 0;
}
            
            
            
        