結果

問題 No.31 悪のミックスジュース
ユーザー pekempeypekempey
提出日時 2015-08-28 10:45:00
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 11 ms / 5,000 ms
コード長 992 bytes
コンパイル時間 1,196 ms
コンパイル使用メモリ 146,500 KB
実行使用メモリ 19,432 KB
最終ジャッジ日時 2023-10-12 17:18:27
合計ジャッジ時間 2,199 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
19,212 KB
testcase_01 AC 10 ms
19,432 KB
testcase_02 AC 10 ms
19,288 KB
testcase_03 AC 11 ms
19,204 KB
testcase_04 AC 11 ms
19,284 KB
testcase_05 AC 10 ms
19,216 KB
testcase_06 AC 2 ms
4,352 KB
testcase_07 AC 10 ms
19,304 KB
testcase_08 AC 11 ms
19,424 KB
testcase_09 AC 11 ms
19,368 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 8 ms
19,300 KB
testcase_12 AC 9 ms
19,216 KB
testcase_13 AC 8 ms
19,220 KB
testcase_14 AC 10 ms
19,412 KB
testcase_15 AC 8 ms
19,340 KB
testcase_16 AC 9 ms
19,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, a) rep2 (i, 0, a)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define repr(i, a) repr2 (i, 0, a)
#define repr2(i, a, b) for (int i = (b) - 1; i >= (a); i--)
using namespace std;
typedef long long ll;

const ll inf = 1e18;
ll dp[101][20202];

int main() {
	ll N, V;
	cin >> N >> V;
	vector<ll> C(N);	
	rep (i, N) cin >> C[i];
	partial_sum(C.begin(), C.end(), C.begin());

	if (V <= N) {
		cout << C[N - 1] << endl;
		return 0;
	}
	V -= N;

	int mini = 0;
	rep (i, N) {
		if (C[mini] * (i + 1) > C[i] * (mini + 1)) mini = i;
	}

	rep (i, 101) rep (j, 20202) dp[i][j] = inf;
	dp[0][0] = 0;

	rep2 (i, 1, N + 1) {
		rep (j, 20202) {
			dp[i][j] = dp[i - 1][j];
			if (j - i >= 0) {
				dp[i][j] = min(dp[i][j], dp[i][j - i] + C[i - 1]);
			}
		}
	}

	ll ans;
	if (V >= 15151) {
		ll x = (V - 15151) / (mini + 1);
		ans = x * C[mini] + dp[N][V - (mini + 1) * x];
	} else {
		ans = dp[N][V];
	}
	ans += C[N - 1];
	cout << ans << endl;

	return 0;
}
0