結果

問題 No.3302 Sense Battle
ユーザー くらげ
提出日時 2025-08-25 18:02:24
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 203 ms / 2,000 ms
コード長 786 bytes
コンパイル時間 2,236 ms
コンパイル使用メモリ 201,036 KB
実行使用メモリ 199,040 KB
最終ジャッジ日時 2025-08-25 18:02:31
合計ジャッジ時間 6,226 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)

void chmax(ll& x,ll y){
    if(x<y) x=y;
    return;
}

int main(){
    int n;
    cin >> n;
    vector<ll> a(n),b(n);
    rep(i,n) cin >> a[i] >> b[i];

    assert(1<=n&&n<=5000);
    rep(i,n){
        assert(1<=a[i]&&a[i]<=1000000000);
        assert(1<=b[i]&&b[i]<=1000000000);
    }

    reverse(a.begin(),a.end());
    reverse(b.begin(),b.end());

    vector<vector<ll>> dp(n+5,vector<ll>(n+5,-2e18)); // dp[i][j]:= 後ろから見て i 枚目までで j 回攻撃
    dp[0][0]=0;
    rep(i,n) rep(j,n+1){
        chmax(dp[i+1][j],dp[i][j]+a[i]*j);
        chmax(dp[i+1][j+1],dp[i][j]+b[i]);
    }

    ll ans=0;
    rep(i,n+1) chmax(ans,dp[n][i]);
    cout << ans << endl;

}
0