結果

問題 No.3302 Sense Battle
ユーザー GOTKAKO
提出日時 2025-10-09 09:16:41
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 93 ms / 2,000 ms
コード長 546 bytes
コンパイル時間 2,032 ms
コンパイル使用メモリ 200,828 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-10-09 09:16:46
合計ジャッジ時間 4,719 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int N; cin >> N;
    vector<pair<long long,long long>> AB(N);
    for(auto &[a,b] : AB) cin >> a >> b;
 
    vector<long long> dp(N+1);
    for(auto [a,b] : AB){
        vector<long long> next(N+1);
        for(int k=0; k<=N; k++){
            if(k) next.at(k-1) = max(next.at(k-1),dp.at(k)+b);
            next.at(k) = max(next.at(k),dp.at(k)+a*k);
        }
        swap(dp,next);
    }

    cout << dp.at(0) << endl;
}
0