結果

問題 No.1715 Dinner 2
ユーザー tamatotamato
提出日時 2021-10-22 22:06:29
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,010 bytes
コンパイル時間 168 ms
コンパイル使用メモリ 81,732 KB
実行使用メモリ 75,172 KB
最終ジャッジ日時 2023-10-24 13:16:45
合計ジャッジ時間 3,844 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,496 KB
testcase_01 AC 36 ms
53,496 KB
testcase_02 AC 42 ms
59,680 KB
testcase_03 AC 36 ms
53,496 KB
testcase_04 AC 41 ms
59,660 KB
testcase_05 AC 40 ms
59,224 KB
testcase_06 AC 35 ms
53,496 KB
testcase_07 AC 40 ms
59,660 KB
testcase_08 AC 41 ms
59,228 KB
testcase_09 AC 36 ms
53,496 KB
testcase_10 AC 43 ms
59,660 KB
testcase_11 AC 123 ms
70,140 KB
testcase_12 AC 113 ms
70,140 KB
testcase_13 AC 96 ms
68,092 KB
testcase_14 AC 107 ms
70,140 KB
testcase_15 AC 113 ms
70,140 KB
testcase_16 AC 111 ms
70,140 KB
testcase_17 AC 91 ms
70,140 KB
testcase_18 AC 49 ms
66,028 KB
testcase_19 AC 47 ms
63,968 KB
testcase_20 AC 46 ms
63,976 KB
testcase_21 AC 43 ms
61,784 KB
testcase_22 AC 45 ms
63,904 KB
testcase_23 AC 50 ms
67,936 KB
testcase_24 AC 48 ms
66,028 KB
testcase_25 AC 55 ms
66,020 KB
testcase_26 AC 55 ms
68,068 KB
testcase_27 AC 52 ms
66,020 KB
testcase_28 AC 54 ms
66,020 KB
testcase_29 AC 54 ms
66,020 KB
testcase_30 AC 54 ms
66,020 KB
testcase_31 AC 54 ms
66,020 KB
testcase_32 AC 143 ms
73,108 KB
testcase_33 AC 142 ms
72,188 KB
testcase_34 AC 157 ms
75,172 KB
testcase_35 AC 152 ms
72,188 KB
testcase_36 AC 37 ms
53,496 KB
testcase_37 WA -
testcase_38 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    N, D = map(int, input().split())
    P = []
    Q = []
    for _ in range(N):
        p, q = map(int, input().split())
        P.append(p)
        Q.append(q)

    ok = -10 ** 9
    ng = 0
    mid = (ok + ng) // 2
    while ng - ok > 1:
        prev = -1
        cur = 0
        flg = 1
        for d in range(D):
            i_best = -1
            cur_best = -10 ** 9
            for i in range(N):
                if cur - P[i] < mid:
                    continue
                if prev == i:
                    continue
                cur_new = cur - P[i] + Q[i]
                if cur_new < mid:
                    continue
                if cur_new > cur_best:
                    cur_best = cur_new
                    i_best = i
            if i_best == -1:
                flg = 0
                break
            else:
                if d == 0:
                    i_best_first = i_best
            prev = i_best
            cur = cur_best
        if flg == 0:
            prev = i_best_first
            cur = 0
            flg = 1
            for d in range(D):
                i_best = -1
                cur_best = -10 ** 9
                for i in range(N):
                    if cur - P[i] < mid:
                        continue
                    if prev == i:
                        continue
                    cur_new = cur - P[i] + Q[i]
                    if cur_new < mid:
                        continue
                    if cur_new > cur_best:
                        cur_best = cur_new
                        i_best = i
                if i_best == -1:
                    flg = 0
                    break
                prev = i_best
                cur = cur_best
            if flg:
                ok = mid
            else:
                ng = mid
        else:
            ok = mid
        mid = (ok + ng) // 2
    print(ok)


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