結果

問題 No.798 コレクション
ユーザー moririn2528_cmoririn2528_c
提出日時 2019-03-15 23:09:26
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 883 bytes
コンパイル時間 677 ms
コンパイル使用メモリ 80,960 KB
実行使用メモリ 19,316 KB
最終ジャッジ日時 2023-09-14 14:09:09
合計ジャッジ時間 1,989 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
19,060 KB
testcase_01 AC 7 ms
19,056 KB
testcase_02 AC 7 ms
19,084 KB
testcase_03 AC 7 ms
19,044 KB
testcase_04 AC 7 ms
19,156 KB
testcase_05 AC 7 ms
19,120 KB
testcase_06 AC 7 ms
19,084 KB
testcase_07 AC 7 ms
19,280 KB
testcase_08 AC 7 ms
19,140 KB
testcase_09 AC 7 ms
19,088 KB
testcase_10 AC 7 ms
19,128 KB
testcase_11 AC 7 ms
19,080 KB
testcase_12 AC 7 ms
19,136 KB
testcase_13 AC 9 ms
19,080 KB
testcase_14 AC 10 ms
19,172 KB
testcase_15 AC 10 ms
19,076 KB
testcase_16 AC 9 ms
19,184 KB
testcase_17 AC 9 ms
19,112 KB
testcase_18 AC 10 ms
19,072 KB
testcase_19 AC 10 ms
19,112 KB
testcase_20 AC 8 ms
19,180 KB
testcase_21 AC 9 ms
19,284 KB
testcase_22 AC 9 ms
19,152 KB
testcase_23 AC 7 ms
19,044 KB
testcase_24 AC 11 ms
19,304 KB
testcase_25 AC 11 ms
19,316 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0