結果

問題 No.798 コレクション
ユーザー やむなくやむなく
提出日時 2019-03-15 21:54:00
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 800 bytes
コンパイル時間 1,388 ms
コンパイル使用メモリ 154,264 KB
実行使用メモリ 23,904 KB
最終ジャッジ日時 2023-09-14 13:29:38
合計ジャッジ時間 2,730 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 11 ms
12,384 KB
testcase_14 AC 16 ms
17,804 KB
testcase_15 AC 14 ms
15,692 KB
testcase_16 AC 8 ms
9,080 KB
testcase_17 AC 12 ms
12,508 KB
testcase_18 AC 21 ms
22,864 KB
testcase_19 AC 17 ms
18,576 KB
testcase_20 AC 8 ms
9,072 KB
testcase_21 AC 7 ms
8,256 KB
testcase_22 AC 14 ms
15,684 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 22 ms
23,904 KB
testcase_25 AC 22 ms
23,872 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  int n;
  cin >> n;
  vector<pair<LL,LL>> p(n);
  for(int i=0;i<n;i++){
    cin >> p[i].second >> p[i].first;
  }
  sort(all(p),greater<pair<LL,LL>>());
  int d=0,c=0;
  for(;d+c<n;d++) if(d%2) c++;
  // cout << d << endl;
  vector<vector<LL>> dp(n+1,vector<LL>(d+1,LINF));
  for(int i=0;i<=n;i++){
    dp[i][0]=0;
  }
  for(int i=1;i<=n;i++){
    for(int j=1;j<=d;j++){
      dp[i][j]=min(dp[i-1][j],dp[i-1][j-1]+p[i-1].second+p[i-1].first*(j-1));
      // cout << dp[i][j] << " ";
    }
    // cout << endl;
  }
  cout << dp[n][d] << endl;
  return 0;
}
0