結果

問題 No.798 コレクション
ユーザー snrnsidysnrnsidy
提出日時 2021-05-27 02:54:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 837 bytes
コンパイル時間 2,759 ms
コンパイル使用メモリ 212,040 KB
実行使用メモリ 34,944 KB
最終ジャッジ日時 2024-04-23 19:20:53
合計ジャッジ時間 4,488 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
34,816 KB
testcase_01 AC 24 ms
34,944 KB
testcase_02 AC 12 ms
34,732 KB
testcase_03 AC 25 ms
34,816 KB
testcase_04 AC 12 ms
34,704 KB
testcase_05 AC 24 ms
34,816 KB
testcase_06 AC 11 ms
34,744 KB
testcase_07 AC 24 ms
34,688 KB
testcase_08 AC 11 ms
34,752 KB
testcase_09 AC 24 ms
34,816 KB
testcase_10 AC 12 ms
34,816 KB
testcase_11 AC 25 ms
34,816 KB
testcase_12 AC 11 ms
34,840 KB
testcase_13 AC 26 ms
34,688 KB
testcase_14 AC 15 ms
34,832 KB
testcase_15 AC 27 ms
34,944 KB
testcase_16 AC 13 ms
34,816 KB
testcase_17 AC 27 ms
34,816 KB
testcase_18 AC 15 ms
34,816 KB
testcase_19 AC 28 ms
34,816 KB
testcase_20 AC 13 ms
34,816 KB
testcase_21 AC 26 ms
34,944 KB
testcase_22 AC 14 ms
34,816 KB
testcase_23 AC 24 ms
34,816 KB
testcase_24 AC 15 ms
34,816 KB
testcase_25 AC 28 ms
34,816 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
 
using namespace std;

int n;

bool cmp(pair<long long int,long long int> a,pair<long long int,long long int> b)
{
	return a.second > b.second;
}

long long int dp[2001][2001];

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	vector <pair<long long int,long long int>> v;
	long long int a,b;

	cin >> n;

	for(int i=0;i<n;i++)
	{
		cin >> a >> b;
		v.push_back(make_pair(a,b));
	}

	sort(v.begin(),v.end(),cmp);

	for(int i=0;i<=2000;i++)
	{
		for(int j=0;j<=2000;j++)
		{
			dp[i][j] = 1e18;
		}
	}
	dp[0][0] = 0;

	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<=(n/3);j++)
		{
			dp[i][j] = min(dp[i][j],dp[i-1][j] + v[i-1].first + ((i-j-1)*v[i-1].second));
			if(j!=0)
			{
				dp[i][j] = min(dp[i][j],dp[i-1][j-1]);
			}
		}
	}

	cout << dp[n][n/3] << '\n';
	return 0;
}
0