結果

問題 No.2693 Sword
ユーザー forest3
提出日時 2024-07-16 16:29:52
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 795 bytes
コンパイル時間 1,689 ms
コンパイル使用メモリ 176,008 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-07-16 16:29:56
合計ジャッジ時間 3,046 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 18 WA * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/math>
using namespace atcoder;

using ll = long long;
#define rep(i, n) for(int i = 0; i < n; i++)

int main() {
	int N, k;
	ll P;
	cin >> N >> P >> k;
	vector<int> t(N), b(N);
	rep(i, N) cin >> t[i] >> b[i];
	ll ans = 0, ma = 1e18;
	vector<vector<ll>> dp(N + 1, vector<ll>(k + 1));
	rep(i, N + 1) dp[i][0] = P;
	rep(i, N + 1) {
		rep(j, i) {
			if(j + 1 > k) break;
			int ii = i - 1;
			if(t[ii] == 1) dp[i][j + 1] = max(dp[i][j + 1], dp[i - 1][j] + b[ii]);
			else dp[i][j + 1] = max(dp[i][j + 1], dp[i - 1][j] * 2);
			if(dp[i][j + 1] > ma) {
				ans = -1;
				break;
			}
		}
		if(ans < 0) break;
	}
	if(ans < 0) {
		cout << -1 << endl;
		return 0;
	}
	rep(i, N + 1) {
		ans = max(ans, dp[i][k]);
	}
	cout << ans << endl;
}


0