結果

問題 No.798 コレクション
ユーザー Bwambocos
提出日時 2019-03-16 12:28:02
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 66 ms / 2,000 ms
コード長 807 bytes
コンパイル時間 1,925 ms
コンパイル使用メモリ 180,040 KB
実行使用メモリ 34,688 KB
最終ジャッジ日時 2024-07-01 22:26:40
合計ジャッジ時間 3,237 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

const LL inf = 1123456789012345678;
LL N;
std::vector<std::pair<LL, LL>>item;
std::vector<std::vector<LL>>memo;

LL dp(LL i, LL j)
{
	if (i == N)
	{
		if (j == N - N / 3) return 0;
		return inf;
	}
	if (memo[i][j] != -1) return memo[i][j];
	LL res1 = dp(i + 1, j), res2 = dp(i + 1, j + 1) + item[i].second + item[i].first*j;
	return memo[i][j] = std::min(res1, res2);
}

int main()
{
	in >> N;
	std::vector<LL>A(N), B(N);
	rep(i, N) in >> A[i] >> B[i];

	rep(i, N) item.push_back(std::make_pair(B[i], A[i]));
	std::sort(item.begin(), item.end(), std::greater<std::pair<LL, LL>>());
	memo.resize(N);
	rep(i, memo.size()) memo[i].resize(N, -1);
	out << dp(0, 0) << std::endl;
}
0