結果
問題 |
No.798 コレクション
|
ユーザー |
|
提出日時 | 2019-03-15 22:55:00 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 6 ms / 2,000 ms |
コード長 | 696 bytes |
コンパイル時間 | 963 ms |
コンパイル使用メモリ | 79,760 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-01 21:24:20 |
合計ジャッジ時間 | 1,872 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 |
ソースコード
#include<iostream> #include<vector> #include<algorithm> using namespace std; typedef long long ll; int main(){ int n; cin >> n; vector<pair<int,int>> v; int a, b; for(int i = 0; i < n; i++){ cin >> a >> b; v.push_back(make_pair(a,b)); } sort(v.rbegin(), v.rend(), [](pair<int,int> p, pair<int,int> q){return p.second < q.second;}); int buy = n/3*2 + n%3; vector<ll> dp(buy, 1ll<<60); for(int i = 0; i < n; i++){ for(int j = buy-1; j > 0; j--){ dp[j] = min(dp[j], dp[j-1]+v[i].first+(ll)v[i].second*j); } dp[0] = min(dp[0], (ll)v[i].first); } cout << dp[buy-1] << endl; return 0; }