結果

問題 No.3302 Sense Battle
コンテスト
ユーザー kroton
提出日時 2025-10-20 22:12:27
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 652 bytes
コンパイル時間 813 ms
コンパイル使用メモリ 76,944 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-10-20 22:12:30
合計ジャッジ時間 2,494 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;

using ll = long long;

const ll INF = 1ll << 60;

int main() {
  int N;
  cin >> N;
  vector<ll> A(N), B(N);
  for (int i = 0; i < N; i++) cin >> A[i] >> B[i];
  vector<ll> dp(N + 1, -INF);
  dp[0] = 0;
  for (int i = N - 1; i >= 0; i--) {
    vector<ll> ndp(N + 1, -INF);
    for (int j = 0; j <= N; j++) {
      if (dp[j] == -INF) continue;
      // A
      ndp[j] = max(ndp[j], dp[j] + A[i] * j);
      // B
      ndp[j + 1] = max(ndp[j + 1], dp[j] + B[i]);
    }
    dp = ndp;
  }
  ll res = -INF;
  for (int j = 0; j <= N; j++) res = max(res, dp[j]);
  cout << res << endl;
  return 0;
}
0