結果

問題 No.798 コレクション
ユーザー polylogKpolylogK
提出日時 2019-03-15 22:38:06
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 904 bytes
コンパイル時間 1,783 ms
コンパイル使用メモリ 177,484 KB
実行使用メモリ 23,956 KB
最終ジャッジ日時 2023-09-14 13:53:07
合計ジャッジ時間 2,925 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 11 ms
12,292 KB
testcase_14 AC 17 ms
17,872 KB
testcase_15 AC 15 ms
15,744 KB
testcase_16 AC 8 ms
9,044 KB
testcase_17 AC 12 ms
12,632 KB
testcase_18 AC 22 ms
22,812 KB
testcase_19 AC 18 ms
18,624 KB
testcase_20 AC 8 ms
9,088 KB
testcase_21 AC 7 ms
8,272 KB
testcase_22 AC 14 ms
15,724 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 23 ms
23,776 KB
testcase_25 AC 23 ms
23,956 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

int main() {
	int n; scanf("%d", &n); std::vector<int> a(n), b(n);
	std::vector<std::pair<int, int>> vec;
	for(int i = 0; i < n; i++) {
		scanf("%d%d", &a[i], &b[i]);
		
		vec.push_back({b[i], a[i]});
	}
	sort(begin(vec), end(vec)); reverse(begin(vec), end(vec));
	
	int C = 0;
	for(int i = 0, count = n; i < n and count > 0; i++) {
		count--; C++;
		if(i % 2) count--;
	}
	
	std::vector<std::vector<i64>> dp(n + 1, std::vector<i64>(C + 1, 1LL << 60)); dp[0][0] = 0;
	for(int i = 0; i < n; i++) {
		for(int j = 0; j <= C; j++) dp[i + 1][j] = dp[i][j];
		for(int j = 0; j < C; j++) {
			i64 A = vec[i].second, B = vec[i].first;
	
			dp[i + 1][j + 1] = std::min(dp[i + 1][j + 1], dp[i][j] + (A + B * (i64)j));
		}
	}
	printf("%lld\n", dp[n][C]);
	return 0;
}
0