結果

問題 No.2693 Sword
ユーザー addnineaddnine
提出日時 2024-03-22 21:42:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 782 bytes
コンパイル時間 2,120 ms
コンパイル使用メモリ 203,948 KB
実行使用メモリ 10,456 KB
最終ジャッジ日時 2024-03-22 21:42:06
合計ジャッジ時間 3,299 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 1 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 5 ms
10,456 KB
testcase_10 AC 3 ms
6,676 KB
testcase_11 AC 4 ms
8,328 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 3 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 3 ms
6,676 KB
testcase_16 AC 3 ms
6,676 KB
testcase_17 AC 2 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 4 ms
8,340 KB
testcase_20 AC 4 ms
10,172 KB
testcase_21 AC 4 ms
10,436 KB
testcase_22 AC 4 ms
10,376 KB
testcase_23 AC 3 ms
8,140 KB
testcase_24 AC 2 ms
6,676 KB
testcase_25 AC 1 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
testcase_27 AC 2 ms
6,676 KB
testcase_28 AC 2 ms
6,676 KB
testcase_29 AC 2 ms
6,676 KB
testcase_30 AC 2 ms
6,676 KB
testcase_31 AC 2 ms
6,676 KB
testcase_32 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
using ll = long long;
using ld = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;

ll MX = 1e18;
ll dp[1010][1010];

int main() {
    ll N, P, K; cin >> N >> P >> K;
    vector<ll> T(N), B(N);
    for (int i = 0; i < N; i++) cin >> T[i] >> B[i];
    dp[0][0] = P;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= K; j++) {
            ll nxt = (T[i] == 1 ? dp[i][j] + B[i] : dp[i][j] * 2);
            if (nxt > MX) {
                cout << -1 << endl;
                return 0;
            }
            dp[i+1][j+1] = max(dp[i][j+1], nxt);
            dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
        }
    }
    cout << (dp[N][K] > MX ? -1 : dp[N][K]) << endl;
}
0