結果

問題 No.1715 Dinner 2
ユーザー mkawa2mkawa2
提出日時 2021-10-23 12:42:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 272 ms / 2,000 ms
コード長 1,303 bytes
コンパイル時間 156 ms
コンパイル使用メモリ 81,704 KB
実行使用メモリ 75,888 KB
最終ジャッジ日時 2023-10-25 08:36:57
合計ジャッジ時間 5,554 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,488 KB
testcase_01 AC 40 ms
53,488 KB
testcase_02 AC 47 ms
61,952 KB
testcase_03 AC 39 ms
53,488 KB
testcase_04 AC 46 ms
59,764 KB
testcase_05 AC 44 ms
59,048 KB
testcase_06 AC 40 ms
53,488 KB
testcase_07 AC 47 ms
59,760 KB
testcase_08 AC 45 ms
59,056 KB
testcase_09 AC 40 ms
53,488 KB
testcase_10 AC 43 ms
59,764 KB
testcase_11 AC 243 ms
75,800 KB
testcase_12 AC 191 ms
75,748 KB
testcase_13 AC 164 ms
75,780 KB
testcase_14 AC 197 ms
75,820 KB
testcase_15 AC 205 ms
75,772 KB
testcase_16 AC 231 ms
75,888 KB
testcase_17 AC 178 ms
75,696 KB
testcase_18 AC 69 ms
73,544 KB
testcase_19 AC 85 ms
75,616 KB
testcase_20 AC 64 ms
72,312 KB
testcase_21 AC 59 ms
68,196 KB
testcase_22 AC 67 ms
73,036 KB
testcase_23 AC 81 ms
75,608 KB
testcase_24 AC 79 ms
75,804 KB
testcase_25 AC 88 ms
75,484 KB
testcase_26 AC 91 ms
75,524 KB
testcase_27 AC 93 ms
75,580 KB
testcase_28 AC 93 ms
75,528 KB
testcase_29 AC 95 ms
75,544 KB
testcase_30 AC 87 ms
75,492 KB
testcase_31 AC 85 ms
75,340 KB
testcase_32 AC 268 ms
75,840 KB
testcase_33 AC 243 ms
75,856 KB
testcase_34 AC 258 ms
75,812 KB
testcase_35 AC 272 ms
75,824 KB
testcase_36 AC 39 ms
53,488 KB
testcase_37 AC 39 ms
53,488 KB
testcase_38 AC 71 ms
75,360 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
dij = [(0, 1), (1, 0), (0, -1), (-1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = 1 << 63
# md = 998244353
md = 10**9+7

n, d = LI()
pq = LLI(n)

def ok(m):
    mx1, mx2 = 0, -inf
    i1 = -1
    for _ in range(d):
        nmx1 = nmx2 = -inf
        ni1 = -1
        for i, (p, q) in enumerate(pq):
            pre = mx1
            if i == i1: pre = mx2
            if pre-p < m: continue
            cur = pre-p+q
            if cur > nmx1:
                nmx2 = nmx1
                nmx1 = cur
                ni1 = i
            elif cur > nmx2:
                nmx2 = cur
        if nmx1 == -inf: return False
        mx1, mx2, i1 = nmx1, nmx2, ni1
    return True

l, r = -10**9, 0
while l+1 < r:
    m = (l+r)//2
    if ok(m): l = m
    else: r = m
print(l)
0