結果
問題 |
No.3302 Sense Battle
|
ユーザー |
![]() |
提出日時 | 2025-10-05 13:49:57 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 226 ms / 2,000 ms |
コード長 | 1,575 bytes |
コンパイル時間 | 5,162 ms |
コンパイル使用メモリ | 335,156 KB |
実行使用メモリ | 199,040 KB |
最終ジャッジ日時 | 2025-10-05 13:50:21 |
合計ジャッジ時間 | 9,221 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 18 |
ソースコード
#include <bits/stdc++.h> using namespace std; #include <atcoder/all> using namespace atcoder; using mint = atcoder::modint998244353; // using mint = double; #define rep(i, l, r) for (int i = (int)(l); i<(int)(r); i++) #define ll long long #define ld long double #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define siz(x) (int)(x).size() template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } const int inf = 1e9; const ll INF = 4e18; template<class T> using pq = priority_queue<T, vector<T>, less<T>>; template<class T> using spq = priority_queue<T, vector<T>, greater<T>>; vector<int> di = {0, 0, 1, -1}; vector<int> dj = {1, -1, 0, 0}; struct Edge { int to, cost; }; void solve() { int N; cin >> N; //dp[i][j] = 今iターン目で、iターン目も含めてこれからj回攻撃するときのmax ll A[N], B[N]; rep(i, 0, N) cin >> B[i] >> A[i]; vector dp(N+1, vector<ll>(N+1, -INF)); dp[N][0] = 0; for (int i = N-1; i >= 0; i--) { rep(j, 0, N+1) { //攻撃する if (j > 0) { dp[i][j] = dp[i+1][j-1] + A[i]; } chmax(dp[i][j], dp[i+1][j] + j * B[i]); } } ll ans = 0; rep(i, 0, N+1) chmax(ans, dp[0][i]); cout << ans << endl; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int T = 1; // cin >> T; while(T--) { solve(); } }