結果

問題 No.798 コレクション
ユーザー 双六双六
提出日時 2020-07-21 03:34:18
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 330 ms / 2,000 ms
コード長 781 bytes
コンパイル時間 395 ms
コンパイル使用メモリ 86,940 KB
実行使用メモリ 169,456 KB
最終ジャッジ日時 2023-08-26 19:15:45
合計ジャッジ時間 5,936 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
71,372 KB
testcase_01 AC 79 ms
71,328 KB
testcase_02 AC 82 ms
71,288 KB
testcase_03 AC 78 ms
71,520 KB
testcase_04 AC 81 ms
71,360 KB
testcase_05 AC 80 ms
71,528 KB
testcase_06 AC 79 ms
71,376 KB
testcase_07 AC 81 ms
71,528 KB
testcase_08 AC 83 ms
71,316 KB
testcase_09 AC 81 ms
71,328 KB
testcase_10 AC 81 ms
71,500 KB
testcase_11 AC 81 ms
71,384 KB
testcase_12 AC 80 ms
71,528 KB
testcase_13 AC 187 ms
102,492 KB
testcase_14 AC 242 ms
134,868 KB
testcase_15 AC 222 ms
117,660 KB
testcase_16 AC 132 ms
86,404 KB
testcase_17 AC 189 ms
102,468 KB
testcase_18 AC 327 ms
166,356 KB
testcase_19 AC 265 ms
131,916 KB
testcase_20 AC 168 ms
95,776 KB
testcase_21 AC 162 ms
96,416 KB
testcase_22 AC 245 ms
131,696 KB
testcase_23 AC 82 ms
71,320 KB
testcase_24 AC 232 ms
134,488 KB
testcase_25 AC 330 ms
169,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys; input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
INF = float("inf")

def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N = int(input())
	items = []
	for i in range(N):
		A, B = getlist()
		items.append([B, A])

	items.sort(reverse = True)

	day = None
	if N % 3 == 0:
		day = int(N * 2 // 3)
	elif N % 3 == 1:
		day = int(N // 3) * 2 + 1
	else:
		day = int((N + 1) * 2 // 3)

	DP = [[INF] * (N + 1) for i in range(N + 1)]
	DP[0][0] = 0
	for i in range(N):
		b, a = items[i]
		for j in range(N):
			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] + a + j * b)

	# print(DP)
	ans = DP[N][day]
	print(ans)

if __name__ == '__main__':
	main()
0