結果
| 問題 |
No.798 コレクション
|
| コンテスト | |
| ユーザー |
momoyuu
|
| 提出日時 | 2024-10-06 18:40:29 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 22 ms / 2,000 ms |
| コード長 | 964 bytes |
| コンパイル時間 | 1,089 ms |
| コンパイル使用メモリ | 104,328 KB |
| 実行使用メモリ | 24,192 KB |
| 最終ジャッジ日時 | 2024-10-06 18:40:31 |
| 合計ジャッジ時間 | 2,219 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 23 |
ソースコード
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n;
cin>>n;
vector<ll> a(n),b(n);
for(int i = 0;i<n;i++) cin>>a[i]>>b[i];
int buy = 0;
{
int res = n;
while(res>0){
buy++;
res--;
if(buy%2==0) res--;
}
}
vector<vector<ll>> dp(n+1,vector<ll>(buy+1,1e18));
dp[0][0] = 0;
vector<int> idx(n);
for(int i = 0;i<n;i++) idx[i] = i;
sort(idx.begin(),idx.end(),[&](int i,int j){
return b[i] > b[j];
});
for(int i = 0;i<n;i++){
for(int j = 0;j<=buy;j++){
dp[i+1][j] = min(dp[i+1][j],dp[i][j]);
if(j==buy) continue;
int ni = idx[i];
ll cost = a[ni] + j * b[ni];
dp[i+1][j+1] = min(dp[i+1][j+1],dp[i][j]+cost);
}
}
cout<<dp[n][buy]<<endl;
}
momoyuu