結果

問題 No.3302 Sense Battle
ユーザー 00 Sakuda
提出日時 2025-10-09 03:28:10
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 666 bytes
コンパイル時間 1,499 ms
コンパイル使用メモリ 113,652 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-10-09 03:28:14
合計ジャッジ時間 3,320 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <numeric>
using namespace std;
using ll = long long;
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, -1);
	dp[0] = 0;
	for (int i = N-1;i >= 0;i--) {
		vector<ll> ndp(N+1, -1);
		for (int j = 0;j <= N;j++) {
			if (dp[j] < 0) continue;
			//use a
			ndp[j] = max(ndp[j], dp[j] + ((ll)j * A[i]));
			//useb
			if (j+1 <= N) ndp[j+1] = max(ndp[j+1], dp[j] + B[i]);
		}
		swap(dp, ndp);
	}
	ll res = 0;
	for (int i = 0;i <= N;i++) res = max(res, dp[i]);
	cout << res << endl;
}
0