結果

問題 No.31 悪のミックスジュース
ユーザー btk
提出日時 2015-05-11 09:36:17
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 100 ms / 5,000 ms
コード長 757 bytes
コンパイル時間 542 ms
コンパイル使用メモリ 62,172 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-09-14 15:50:20
合計ジャッジ時間 2,419 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define LL long long

const LL INF=(LL)1e9*(LL)1e9;

vector<LL> dp(1000001,INF);
int main(void){
	int N;LL V;
	cin>>N>>V;
	LL c[100];
	LL s[100];
	for(int i=0;i<N;i++)
		cin>>c[i];

	s[0]=c[0];
	double T=s[0];
	int index=0;
	for(int i=1;i<N;i++){
		s[i]=s[i-1]+c[i];
		if(T>s[i]/(double)(i+1)){
			index=i;
			T=s[i]/(double)(i+1);
		}
	}
	//cout<<index<<endl;
	V=max(V-N,0ll);
	dp[0]=0;
	for(int i=0;i<N;i++)
		for(int j=i+1;j<=1000000;j++)
			dp[j]=min(dp[j],dp[j-(i+1)]+s[i]);
	LL res=INF;
	for(int i=0;i<=1000000;i++){
		res=min(res,dp[i]+((max(V-i,0ll)+index)/(index+1))*s[index]);
		//cout<<((max(V-i,0ll)+index)/(index+1))<<endl;
	}
	cout<<res+s[N-1]<<endl;
	return 0;
}

0