結果
| 問題 | No.798 コレクション |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-03-15 21:59:57 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 22 ms / 2,000 ms |
| コード長 | 910 bytes |
| 記録 | |
| コンパイル時間 | 2,177 ms |
| コンパイル使用メモリ | 198,280 KB |
| 最終ジャッジ日時 | 2025-01-06 22:22:24 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 23 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
void chmin(int64_t& a, int64_t b){
a = min(a, b);
}
int main(){
int N;
pair<int, int> BA[2000];
cin >> N;
for(int i=0; i<N; i++){
int a, b;
cin >> a >> b;
BA[i] = {b, a};
}
sort(BA, BA+N, greater<>());
int M = 0, get = 0;
while(get < N){
M++;
get++;
if(M % 2 == 0) get++;
}
const int64_t INF = 1e18;
static int64_t dp[2010][2010];
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++){
int b = BA[i].first, a = BA[i].second;
for(int j=0; j<=M; j++){
chmin(dp[i+1][j], dp[i][j]);
if(j < M){
int64_t result = dp[i][j] + a + b*j;
chmin(dp[i+1][j+1], result);
}
}
}
cout << dp[N][M] << endl;
return 0;
}