結果

問題 No.974 最後の日までに
ユーザー tcltktcltk
提出日時 2021-07-03 06:30:27
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,589 ms / 2,000 ms
コード長 4,391 bytes
コンパイル時間 519 ms
コンパイル使用メモリ 87,264 KB
実行使用メモリ 229,612 KB
最終ジャッジ日時 2023-09-12 12:10:07
合計ジャッジ時間 41,802 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,072 ms
229,472 KB
testcase_01 AC 1,567 ms
229,608 KB
testcase_02 AC 1,474 ms
229,436 KB
testcase_03 AC 1,485 ms
229,340 KB
testcase_04 AC 1,476 ms
229,316 KB
testcase_05 AC 1,507 ms
229,320 KB
testcase_06 AC 1,538 ms
229,368 KB
testcase_07 AC 1,490 ms
229,536 KB
testcase_08 AC 1,487 ms
229,324 KB
testcase_09 AC 1,471 ms
229,572 KB
testcase_10 AC 1,465 ms
229,612 KB
testcase_11 AC 1,444 ms
229,304 KB
testcase_12 AC 1,432 ms
229,236 KB
testcase_13 AC 1,473 ms
229,412 KB
testcase_14 AC 1,463 ms
229,188 KB
testcase_15 AC 1,440 ms
229,608 KB
testcase_16 AC 1,428 ms
229,300 KB
testcase_17 AC 249 ms
84,688 KB
testcase_18 AC 245 ms
84,748 KB
testcase_19 AC 243 ms
84,864 KB
testcase_20 AC 248 ms
84,856 KB
testcase_21 AC 246 ms
84,756 KB
testcase_22 AC 247 ms
84,432 KB
testcase_23 AC 250 ms
84,196 KB
testcase_24 AC 248 ms
84,436 KB
testcase_25 AC 232 ms
83,360 KB
testcase_26 AC 240 ms
83,460 KB
testcase_27 AC 1,462 ms
204,236 KB
testcase_28 AC 1,550 ms
229,372 KB
testcase_29 AC 276 ms
81,056 KB
testcase_30 AC 266 ms
84,864 KB
testcase_31 AC 217 ms
80,808 KB
testcase_32 AC 216 ms
80,844 KB
testcase_33 AC 1,029 ms
163,640 KB
testcase_34 AC 1,589 ms
229,428 KB
testcase_35 AC 217 ms
80,924 KB
testcase_36 AC 218 ms
81,116 KB
testcase_37 AC 300 ms
86,880 KB
testcase_38 AC 217 ms
80,876 KB
testcase_39 AC 218 ms
81,012 KB
testcase_40 AC 230 ms
83,336 KB
testcase_41 AC 236 ms
84,200 KB
testcase_42 AC 319 ms
89,116 KB
testcase_43 AC 323 ms
88,904 KB
testcase_44 AC 318 ms
87,856 KB
testcase_45 AC 320 ms
88,980 KB
testcase_46 AC 217 ms
80,920 KB
testcase_47 AC 219 ms
81,060 KB
testcase_48 AC 224 ms
81,004 KB
testcase_49 AC 220 ms
81,004 KB
testcase_50 AC 219 ms
81,008 KB
testcase_51 AC 218 ms
80,976 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# from typing import *

import sys
import io
import math
import collections
import decimal
import itertools
import bisect
import heapq


def input():
    return sys.stdin.readline()[:-1]


# sys.setrecursionlimit(1000000)

# _INPUT = """52
# 3316937975 948971987273 245356275212
# 7622812803 165560224258 237733462410
# 5049794700 725262318970 236000605685
# 4601698392 10569666447 239021720096
# 976650 203973357560 244070538145
# 6750896419 743731276134 241921340119
# 6672133707 96027496166 235250183063
# 6141923153 188257360777 235859156328
# 2377616496 835017164869 240153673539
# 3697283028 188448574493 242598313666
# 6997091419 57289443968 237978838743
# 5481244831 858935768046 236194876939
# 7582706228 266693610721 235609262128
# 806840622 645244514026 240283666340
# 7225545701 905847830553 240640826864
# 8312979195 764407581858 233134688292
# 8939241886 968933490364 231420992109
# 3661208074 515347058892 236072763228
# 2031892049 66512164290 242980113066
# 6095986014 699428791235 240545335127
# 3940372534 193748065544 238636854641
# 5603786625 113723605765 239129054028
# 7493777737 620274173901 235575648828
# 9619303168 95205614004 231560132285
# 6445461447 420813714741 232608448575
# 3436603117 448753477910 238791148624
# 5349268149 561710581962 239887341920
# 3883766620 75266996501 239440178421
# 1445171801 13320184566 243344274768
# 1419672038 108596353216 245808369350
# 970068159 526852966793 246283472991
# 2640836137 204086515400 245062308892
# 2788233781 307455107129 243244143269
# 7177164357 79179860484 238707815051
# 9084820943 665454039325 232411227890
# 4340686688 304039018989 235247705556
# 3257845220 388040361266 241074681282
# 648273444 718491850531 244767094525
# 6844189839 141803564246 241180749907
# 9575488316 894353898470 232253535034
# 7509360687 783182841936 231588364187
# 4313440218 732960840861 236850412283
# 6036068327 650944036934 238323704644
# 564458036 49332764755 242072686825
# 7743489054 986082188868 240365266098
# 857041410 222310922549 240072682725
# 173403905 161280832828 247642767872
# 4233911554 520867603733 244265897729
# 7715877116 736893921793 236723424520
# 8289333109 560874966506 232668002963
# 1720010053 446542113739 238663870025
# 185220255 277985184334 246767982882

# """
# sys.stdin = io.StringIO(_INPUT)


W = int(input())
A, B, C = [], [], []
for _ in range(W):
    a, b, c = map(int, input().split())
    A.append(a)
    B.append(b)
    C.append(c)
A.append(0)
B.append(0)
C.append(0)

N1 = W//2
N2 = W-N1

dp1 = [collections.defaultdict(int) for _ in range(N1+2)]
dp1[0][0] = 0
for day in range(N1):
    for money, love in dp1[day].items():
        # 学校 -> デート
        dp1[day+2][money-C[day+1]] = max(dp1[day+2][money-C[day+1]], love+B[day+1])

        # アルバイト
        dp1[day+1][money+A[day]] = max(dp1[day+1][money+A[day]], love)

dp2a = [collections.defaultdict(int) for _ in range(N2+2)]
dp2a[0][0] = 0
for day in range(N2):
    for money, love in dp2a[day].items():
        # 学校 -> デート
        dp2a[day+2][money-C[N1+day+1]] = max(dp2a[day+2][money-C[N1+day+1]], love+B[N1+day+1])

        # アルバイト
        dp2a[day+1][money+A[N1+day]] = max(dp2a[day+1][money+A[N1+day]], love)

dp2b = [collections.defaultdict(int) for _ in range(N2+1)]
dp2b[0][0] = 0
for day in range(N2-1):
    for money, love in dp2b[day].items():
        # 学校 -> デート
        dp2b[day+2][money-C[N1+1+day+1]] = max(dp2b[day+2][money-C[N1+1+day+1]], love+B[N1+1+day+1])

        # アルバイト
        dp2b[day+1][money+A[N1+1+day]] = max(dp2b[day+1][money+A[N1+1+day]], love)

max_love = 0

result2a = list(sorted(dp2a[N2].items()))
max_love2a = [0] * (len(result2a)+1)
for i in reversed(range(len(result2a))):
    max_love2a[i] = max(max_love2a[i+1], result2a[i][1])
for money1, love1 in dp1[N1].items():
    k = bisect.bisect_left(result2a, (-money1, 0))
    if k < len(result2a):
        love2 = max_love2a[k]
        max_love = max(max_love, love1+love2)

result2b = list(sorted(dp2b[N2-1].items()))
max_love2b = [0] * (len(result2b)+1)
for i in reversed(range(len(result2b))):
    max_love2b[i] = max(max_love2b[i+1], result2b[i][1])
for money1, love1 in dp1[N1+1].items():
    k = bisect.bisect_left(result2b, (-money1, 0))
    if k < len(result2b):
        love2 = max_love2b[k]
        max_love = max(max_love, love1+love2)

print(max_love)


0