結果

問題 No.1715 Dinner 2
ユーザー tamatotamato
提出日時 2021-10-22 23:04:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 242 ms / 2,000 ms
コード長 1,607 bytes
コンパイル時間 171 ms
コンパイル使用メモリ 82,032 KB
実行使用メモリ 75,708 KB
最終ジャッジ日時 2023-10-24 14:39:20
合計ジャッジ時間 5,070 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,748 KB
testcase_01 AC 40 ms
59,420 KB
testcase_02 AC 47 ms
62,252 KB
testcase_03 AC 37 ms
53,748 KB
testcase_04 AC 46 ms
62,216 KB
testcase_05 AC 40 ms
59,480 KB
testcase_06 AC 37 ms
53,748 KB
testcase_07 AC 45 ms
62,156 KB
testcase_08 AC 41 ms
59,484 KB
testcase_09 AC 37 ms
53,748 KB
testcase_10 AC 40 ms
59,884 KB
testcase_11 AC 178 ms
75,708 KB
testcase_12 AC 179 ms
75,536 KB
testcase_13 AC 166 ms
75,540 KB
testcase_14 AC 161 ms
75,536 KB
testcase_15 AC 184 ms
75,536 KB
testcase_16 AC 159 ms
75,528 KB
testcase_17 AC 127 ms
75,600 KB
testcase_18 AC 51 ms
68,404 KB
testcase_19 AC 51 ms
70,460 KB
testcase_20 AC 49 ms
66,356 KB
testcase_21 AC 46 ms
64,092 KB
testcase_22 AC 48 ms
68,328 KB
testcase_23 AC 55 ms
73,056 KB
testcase_24 AC 50 ms
68,400 KB
testcase_25 AC 67 ms
75,496 KB
testcase_26 AC 65 ms
75,500 KB
testcase_27 AC 60 ms
72,528 KB
testcase_28 AC 63 ms
73,560 KB
testcase_29 AC 68 ms
75,536 KB
testcase_30 AC 65 ms
75,500 KB
testcase_31 AC 61 ms
73,296 KB
testcase_32 AC 222 ms
75,544 KB
testcase_33 AC 220 ms
75,540 KB
testcase_34 AC 242 ms
75,552 KB
testcase_35 AC 237 ms
75,540 KB
testcase_36 AC 37 ms
53,748 KB
testcase_37 AC 36 ms
53,748 KB
testcase_38 AC 50 ms
72,292 KB
権限があれば一括ダウンロードができます

ソースコード

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-2):
            best = -10 ** 9
            best_i = []
            for i in range(N):
                if cur - P[i] < mid:
                    continue
                if i == prev:
                    continue
                cur_new = cur - P[i] + Q[i]
                if cur_new > best:
                    best_i = [i]
                    best = cur_new
                elif cur_new == best:
                    best_i.append(i)
            if not best_i:
                flg = 0
                break
            if len(best_i) > 1:
                prev = -1
            else:
                prev = best_i[0]
            cur = best

        flg2 = 0
        for i in range(N):
            if i == prev:
                continue
            if cur - P[i] < mid:
                continue
            cur_new_i = cur - P[i] + Q[i]
            for j in range(N):
                if j == i:
                    continue
                if cur_new_i - P[j] >= mid:
                    flg2 = 1
        if flg2 == 0:
            flg = 0

        if flg == 0:
            ng = mid
        else:
            ok = mid
        mid = (ok + ng) // 2
    print(ok)


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