結果
問題 | No.798 コレクション |
ユーザー |
![]() |
提出日時 | 2019-03-16 03:41:38 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 19 ms / 2,000 ms |
コード長 | 555 bytes |
コンパイル時間 | 670 ms |
コンパイル使用メモリ | 71,284 KB |
実行使用メモリ | 34,944 KB |
最終ジャッジ日時 | 2024-07-01 22:17:35 |
合計ジャッジ時間 | 1,658 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 |
ソースコード
#include <iostream> #include <algorithm> #include <utility> using namespace std; typedef long long ll; pair<ll,ll> p[2010]; ll dp[2010][2010] = {}; int main(){ ll i,j,n; cin >> n; for(i=0;i<n;i++){ ll a,b; cin >> a >> b; p[i] = {-b,a}; } sort(p,p+n); for(i=0;i<=n;i++){ for(j=0;j<=n;j++){ dp[i][j] = 10000000000000000; } } dp[0][0] = 0; for(i=1;i<=n;i++){ for(j=0;j<=n;j++){ dp[i][j] = min(dp[i][j],dp[i-1][j]); dp[i][j+1] = min(dp[i][j+1],dp[i-1][j] + p[i-1].second - p[i-1].first*j); } } cout << dp[n][n - n/3] << endl; }