結果
| 問題 | 
                            No.798 コレクション
                             | 
                    
| コンテスト | |
| ユーザー | 
                             monnu
                         | 
                    
| 提出日時 | 2021-04-18 17:18:43 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 23 ms / 2,000 ms | 
| コード長 | 835 bytes | 
| コンパイル時間 | 1,813 ms | 
| コンパイル使用メモリ | 178,240 KB | 
| 実行使用メモリ | 24,192 KB | 
| 最終ジャッジ日時 | 2024-07-04 04:39:24 | 
| 合計ジャッジ時間 | 2,865 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 23 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
using ll=long long;
using Graph=vector<vector<int>>;
#define MAX 200003
#define MOD 1000000007
#define INF 1000000000000000000
int main(){
  int N;
  cin>>N;
  vector<pair<ll,ll>> BA(N);
  for(int i=0;i<N;i++){
    cin>>BA[i].second>>BA[i].first;
  }
  sort(BA.begin(),BA.end());
  reverse(BA.begin(),BA.end());
  int n;
  if(N%3==0){
    n=N*2/3;
  }else if(N%3==1){
    n=(N-1)*2/3+1;
  }else{
    n=(N+1)*2/3;
  }
  vector<vector<ll>> dp(N+1,vector<ll>(n+1,INF));
  dp[0][0]=0;
  for(int i=0;i<N;i++){
    ll A=BA[i].second;
    ll B=BA[i].first;
    for(int j=0;j<=n;j++){
      dp[i+1][j]=dp[i][j];
    }
    for(int j=0;j<n;j++){
      dp[i+1][j+1]=min<ll>(dp[i+1][j+1],dp[i][j]+A+B*(ll)j);
    }
  }
  cout<<dp[N][n]<<endl;
}
            
            
            
        
            
monnu