結果
| 問題 | No.2693 Sword | 
| コンテスト | |
| ユーザー |  ManjushriMitra | 
| 提出日時 | 2024-12-28 16:24:50 | 
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,544 bytes | 
| コンパイル時間 | 4,695 ms | 
| コンパイル使用メモリ | 250,904 KB | 
| 実行使用メモリ | 11,136 KB | 
| 最終ジャッジ日時 | 2024-12-28 16:24:56 | 
| 合計ジャッジ時間 | 4,548 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 WA * 1 | 
| other | AC * 23 WA * 6 | 
ソースコード
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,m,n) for(int i=m; i<int(n); ++i)
#define repll(i,m,n) for(ll i=m; i<ll(n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define fi first
#define se second
template<typename T> bool chmin(T& a, T b){ if(a > b){a = b; return true;} return false; }
template<typename T> bool chmax(T& a, T b){ if(a < b){a = b; return true;} return false; }
template<typename T> T gcd(T a, T b){ return a % b ? gcd(b, a % b) : b; }
template<typename T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, K;
    ll P;
    cin >> N >> P >> K;
    vector<int> T(N);
    vector<ll> B(N);
    rep(i, 0, N) cin >> T[i] >> B[i];
    vector dp(N+1, vector<ll>(K+1, -1LL));
    dp[0][0] = P;
    const ll inf1 = 1000000000000000000LL;
    const ll inf2 = inf1 + 100LL;
    rep(i, 0, N){
        rep(j, 0, K+1){
            if(dp[i][j] == -1LL) continue;
            if(j != K){
                if(T[i] == 1){
                    if(inf1 > dp[i][j] + B[i]) chmax(dp[i+1][j+1], dp[i][j] + B[i]);
                    else chmax(dp[i+1][j+1], inf2);
                }else{
                    if(INT_FAST16_MAX / 2LL > dp[i][j]) chmax(dp[i+1][j+1], 2LL * dp[i][j]);
                    else chmax(dp[i+1][j+1], inf2);
                }
            }
            chmax(dp[i+1][j], dp[i][j]);
        }
    }
    cout << (dp[N][K] == inf2 ? -1 : dp[N][K]) << endl;
    return 0;
}
            
            
            
        