結果

問題 No.798 コレクション
ユーザー beetbeet
提出日時 2019-03-15 21:33:08
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 21 ms / 2,000 ms
コード長 961 bytes
コンパイル時間 2,313 ms
コンパイル使用メモリ 209,636 KB
実行使用メモリ 35,388 KB
最終ジャッジ日時 2023-09-14 13:05:36
合計ジャッジ時間 3,774 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
35,216 KB
testcase_01 AC 12 ms
35,116 KB
testcase_02 AC 12 ms
35,244 KB
testcase_03 AC 11 ms
35,124 KB
testcase_04 AC 12 ms
35,184 KB
testcase_05 AC 11 ms
35,260 KB
testcase_06 AC 11 ms
35,208 KB
testcase_07 AC 12 ms
35,180 KB
testcase_08 AC 11 ms
35,368 KB
testcase_09 AC 12 ms
35,248 KB
testcase_10 AC 12 ms
35,388 KB
testcase_11 AC 11 ms
35,220 KB
testcase_12 AC 11 ms
35,188 KB
testcase_13 AC 15 ms
35,180 KB
testcase_14 AC 18 ms
35,336 KB
testcase_15 AC 17 ms
35,204 KB
testcase_16 AC 15 ms
35,260 KB
testcase_17 AC 16 ms
35,180 KB
testcase_18 AC 19 ms
35,356 KB
testcase_19 AC 18 ms
35,336 KB
testcase_20 AC 14 ms
35,252 KB
testcase_21 AC 14 ms
35,228 KB
testcase_22 AC 17 ms
35,200 KB
testcase_23 AC 11 ms
35,184 KB
testcase_24 AC 20 ms
35,320 KB
testcase_25 AC 21 ms
35,288 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
const Int MAX = 2020;
const Int INF = 1e15;
Int dp[MAX][MAX];
signed main(){
  Int n;
  cin>>n;
  vector<Int> a(n),b(n);
  for(Int i=0;i<n;i++) cin>>a[i]>>b[i];
  {
    using P = pair<Int, Int>;
    vector<P> vp;
    for(Int i=0;i<n;i++) vp.emplace_back(b[i],a[i]);
    sort(vp.rbegin(),vp.rend());
    for(Int i=0;i<n;i++) tie(b[i],a[i])=vp[i];
  }
  
  for(Int i=0;i<MAX;i++)
    for(Int j=0;j<MAX;j++)
      dp[i][j]=INF;

  dp[0][0]=0;
  for(Int i=0;i<n;i++){
    for(Int j=0;j<n;j++){
      chmin(dp[i+1][j],dp[i][j]);
      chmin(dp[i+1][j+1],dp[i][j]+a[i]+b[i]*j);
    }    
  }
  Int ans=INF;
  for(Int j=0;j<=n;j++){
    if(j+(j/2)<n) continue;
    chmin(ans,dp[n][j]);
  }
  cout<<ans<<endl;
  return 0;
}
0