結果
| 問題 |
No.3302 Sense Battle
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-07-09 05:42:47 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 99 ms / 2,000 ms |
| コード長 | 923 bytes |
| コンパイル時間 | 2,177 ms |
| コンパイル使用メモリ | 197,352 KB |
| 実行使用メモリ | 199,136 KB |
| 最終ジャッジ日時 | 2025-07-09 05:42:52 |
| 合計ジャッジ時間 | 4,672 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 18 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
long long dp[5001][5001];
const long long INF = 1LL << 60;
template<class T> inline bool chmax(T &a, T b) { if(a < b) { a = b; return 1; } return 0; }
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n; cin >> n;
vector<long long> a(n), b(n);
for(int i = 0; i < n; i++){
cin >> a[i] >> b[i];
}
reverse(a.begin(), a.end());
reverse(b.begin(), b.end());
for(int i = 0; i <= n; i++){
for(int j = 0; j <= n; j++){
dp[i][j] = -INF;
}
}
dp[0][0] = 0;
for(int i = 0; i < n; i++){
for(int j = 0; j <= i; j++){
chmax(dp[i + 1][j], dp[i][j] + a[i] * j);
chmax(dp[i + 1][j + 1], dp[i][j] + b[i]);
}
}
long long ans = -INF;
for(int i = 0; i <= n; i++){
chmax(ans, dp[n][i]);
}
cout << ans << endl;
return 0;
}