結果

問題 No.2693 Sword
ユーザー tobbie
提出日時 2024-05-04 08:00:46
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 700 bytes
コンパイル時間 1,538 ms
コンパイル使用メモリ 172,292 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-11-25 17:47:07
合計ジャッジ時間 2,620 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

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];
  vector<vector<ll>> dp(N+1, vector<ll> (K+1, 0));
  dp[0][0] = P;
  rep(i, N) {
    rep(j, K+1) {
      // not use
      dp[i+1][j] = dp[i][j];
      // use
      if (j > 0 && j <= i+1) {
	if (T[i] == 1)
	  dp[i+1][j] = max(dp[i][j-1] + B[i], dp[i+1][j]);
	if (T[i] == 2)
	  dp[i+1][j] = max(dp[i][j-1] * 2, dp[i+1][j]);
      }
      if (dp[i+1][j] > (ll)1e18) {
	cout << -1 << endl;
	return 0;
      }
    }
  }
  cout << dp[N][K] << endl;
  return 0;
}
0