結果
| 問題 | 
                            No.798 コレクション
                             | 
                    
| コンテスト | |
| ユーザー | 
                             leaf_1415
                         | 
                    
| 提出日時 | 2019-03-15 21:41:06 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 22 ms / 2,000 ms | 
| コード長 | 656 bytes | 
| コンパイル時間 | 838 ms | 
| コンパイル使用メモリ | 61,120 KB | 
| 実行使用メモリ | 34,704 KB | 
| 最終ジャッジ日時 | 2024-07-01 20:37:22 | 
| 合計ジャッジ時間 | 1,765 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 23 | 
ソースコード
#include <iostream>
#include <utility>
#include <algorithm>
#define llint long long
using namespace std;
llint n;
pair<llint, llint> p[2005];
llint dp[2005][2005];
int main(void)
{
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> p[i].second >> p[i].first;
	sort(p+1, p+n+1);
	reverse(p+1, p+n+1);
	
	
	for(int i = 0; i <= n; i++){
		for(int j = 0; j <= n; j++){
			dp[i][j] = 1e18;
		}
	}
	dp[0][0] = 0;
	
	for(int i = 0; i < n; i++){
		for(int j = 0; j <= n; j++){
			dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
			if(j+1 <= n) dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j] + p[i+1].first*j + p[i+1].second);
		}
	}
	cout << dp[n][n-n/3] << endl;
	
	return 0;
}
            
            
            
        
            
leaf_1415