結果
| 問題 | 
                            No.798 コレクション
                             | 
                    
| コンテスト | |
| ユーザー | 
                             moririn2528_c
                         | 
                    
| 提出日時 | 2019-03-15 23:09:26 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 12 ms / 2,000 ms | 
| コード長 | 883 bytes | 
| コンパイル時間 | 855 ms | 
| コンパイル使用メモリ | 80,948 KB | 
| 実行使用メモリ | 19,224 KB | 
| 最終ジャッジ日時 | 2024-07-01 21:31:40 | 
| 合計ジャッジ時間 | 1,969 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 23 | 
ソースコード
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
typedef pair<LL,int> LP;
vector<P> v1;
LL dp[2005][1005];
int main(){
	int n;
	int i,j,k;
	LL a,b,c;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>a>>b;
		v1.push_back(make_pair(b,a));
	}
	sort(v1.rbegin(),v1.rend());
	memset(dp,-1,sizeof(dp));
	dp[0][0]=0;
	for(i=0;i<n;i++){
		b=v1[i].first,a=v1[i].second;
		for(j=0;j<=n/3;j++){
			if(dp[i][j]==-1)continue;
				dp[i+1][j+1]=dp[i][j];
			c=dp[i][j]+a+b*(i-j);
			if(dp[i+1][j]==-1 || dp[i+1][j]>c)dp[i+1][j]=c;
		}
	}
	a=dp[n][0];
	for(i=0;i<=n/3;i++){
		if(a>dp[n][i])a=dp[n][i];
	}
	cout<<a<<endl;
	return 0;
}
            
            
            
        
            
moririn2528_c