結果

問題 No.974 最後の日までに
ユーザー tcltktcltk
提出日時 2021-07-03 06:25:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,251 ms / 2,000 ms
コード長 4,117 bytes
コンパイル時間 1,821 ms
コンパイル使用メモリ 86,484 KB
実行使用メモリ 168,700 KB
最終ジャッジ日時 2023-09-12 12:03:45
合計ジャッジ時間 48,261 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 692 ms
168,404 KB
testcase_01 AC 1,187 ms
168,336 KB
testcase_02 AC 1,134 ms
168,256 KB
testcase_03 AC 1,161 ms
168,216 KB
testcase_04 AC 1,132 ms
168,680 KB
testcase_05 AC 1,141 ms
168,572 KB
testcase_06 AC 1,196 ms
168,220 KB
testcase_07 AC 1,154 ms
168,424 KB
testcase_08 AC 1,116 ms
168,400 KB
testcase_09 AC 1,124 ms
168,612 KB
testcase_10 AC 1,122 ms
168,452 KB
testcase_11 AC 1,127 ms
168,388 KB
testcase_12 AC 1,104 ms
168,304 KB
testcase_13 AC 1,150 ms
168,680 KB
testcase_14 AC 1,127 ms
168,244 KB
testcase_15 AC 1,091 ms
168,212 KB
testcase_16 AC 1,092 ms
168,320 KB
testcase_17 AC 1,119 ms
168,244 KB
testcase_18 AC 1,124 ms
168,384 KB
testcase_19 AC 1,120 ms
168,608 KB
testcase_20 AC 1,113 ms
168,304 KB
testcase_21 AC 1,115 ms
168,640 KB
testcase_22 AC 1,137 ms
168,700 KB
testcase_23 AC 1,134 ms
168,636 KB
testcase_24 AC 1,146 ms
168,356 KB
testcase_25 AC 222 ms
83,576 KB
testcase_26 AC 225 ms
83,248 KB
testcase_27 AC 1,160 ms
150,196 KB
testcase_28 AC 1,201 ms
168,388 KB
testcase_29 AC 206 ms
80,672 KB
testcase_30 AC 1,221 ms
168,512 KB
testcase_31 AC 203 ms
80,592 KB
testcase_32 AC 207 ms
80,696 KB
testcase_33 AC 828 ms
131,952 KB
testcase_34 AC 1,239 ms
168,320 KB
testcase_35 AC 206 ms
80,908 KB
testcase_36 AC 209 ms
80,700 KB
testcase_37 AC 1,227 ms
168,300 KB
testcase_38 AC 200 ms
80,696 KB
testcase_39 AC 205 ms
80,596 KB
testcase_40 AC 944 ms
150,044 KB
testcase_41 AC 1,004 ms
168,676 KB
testcase_42 AC 1,235 ms
168,316 KB
testcase_43 AC 1,251 ms
168,316 KB
testcase_44 AC 1,184 ms
149,984 KB
testcase_45 AC 833 ms
131,800 KB
testcase_46 AC 208 ms
80,804 KB
testcase_47 AC 205 ms
80,808 KB
testcase_48 AC 206 ms
80,804 KB
testcase_49 AC 208 ms
80,812 KB
testcase_50 AC 211 ms
80,744 KB
testcase_51 AC 207 ms
80,904 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 = [list() for _ in range(N1+2)]
dp1[0].append((0, 0))
for day in range(N1):
    for money, love in dp1[day]:
        # 学校 -> デート
        dp1[day+2].append((money-C[day+1], love+B[day+1]))

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

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

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

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

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

max_love = 0

result2a = sorted(dp2a[N2])
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]:
    k = bisect.bisect_left(result2a, (-money1, 0))
    if k < len(result2a):
        love2 = max_love2a[k]
        max_love = max(max_love, love1+love2)

result2b = sorted(dp2b[N2-1])
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]:
    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