結果
| 問題 | 
                            No.798 コレクション
                             | 
                    
| コンテスト | |
| ユーザー | 
                             tempura_pp
                         | 
                    
| 提出日時 | 2019-03-15 21:43:13 | 
| 言語 | C++17(clang)  (17.0.6 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 21 ms / 2,000 ms | 
| コード長 | 1,117 bytes | 
| コンパイル時間 | 1,334 ms | 
| コンパイル使用メモリ | 144,664 KB | 
| 実行使用メモリ | 34,816 KB | 
| 最終ジャッジ日時 | 2024-11-30 13:42:20 | 
| 合計ジャッジ時間 | 2,598 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 23 | 
ソースコード
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int main(){
	int n;
	cin>>n;
	ll a[n],b[n];
	rep(i,n)cin>>a[i]>>b[i];
	vector<int> ord(n);
	iota(ord.begin(),ord.end(),0);
	sort(ord.begin(),ord.end(),[&](auto x,auto y){
		return b[x]==b[y] ? a[x]>a[y] : b[x]>b[y];
		});
	ll dp[n+1][n+1];
	rep(i,n+1)rep(j,n+1)dp[i][j]=longinf;
	dp[0][0]=0;
	rep(i,n)rep(j,n){
		int idx=ord[i];
		dp[i+1][j+1]=min(dp[i][j]+a[idx]+b[idx]*j,dp[i+1][j+1]);
		dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
		dp[i+1][j+1]=min(dp[i+1][j+1],dp[i][j+1]);
	}
	int m;
	if(n%3==0)m=n/3*2;
	if(n%3==1)m=n/3*2+1;
	if(n%3==2)m=n/3*2+2;
	cout<<dp[n][m]<<endl;
	return 0;
}
            
            
            
        
            
tempura_pp