結果

問題 No.1715 Dinner 2
ユーザー wolgnikwolgnik
提出日時 2021-10-22 22:33:45
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 182 ms / 2,000 ms
コード長 1,672 bytes
コンパイル時間 172 ms
コンパイル使用メモリ 81,668 KB
実行使用メモリ 76,328 KB
最終ジャッジ日時 2023-10-24 13:54:15
合計ジャッジ時間 4,368 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
53,396 KB
testcase_01 AC 42 ms
53,396 KB
testcase_02 AC 39 ms
53,396 KB
testcase_03 AC 37 ms
53,396 KB
testcase_04 AC 38 ms
53,396 KB
testcase_05 AC 38 ms
53,396 KB
testcase_06 AC 38 ms
53,396 KB
testcase_07 AC 38 ms
53,396 KB
testcase_08 AC 38 ms
53,396 KB
testcase_09 AC 38 ms
53,396 KB
testcase_10 AC 38 ms
53,396 KB
testcase_11 AC 125 ms
76,328 KB
testcase_12 AC 125 ms
76,328 KB
testcase_13 AC 115 ms
76,328 KB
testcase_14 AC 135 ms
76,328 KB
testcase_15 AC 111 ms
76,328 KB
testcase_16 AC 132 ms
76,180 KB
testcase_17 AC 105 ms
74,540 KB
testcase_18 AC 66 ms
72,524 KB
testcase_19 AC 67 ms
72,524 KB
testcase_20 AC 64 ms
70,460 KB
testcase_21 AC 59 ms
68,372 KB
testcase_22 AC 68 ms
72,528 KB
testcase_23 AC 68 ms
72,528 KB
testcase_24 AC 67 ms
72,524 KB
testcase_25 AC 73 ms
70,476 KB
testcase_26 AC 69 ms
70,476 KB
testcase_27 AC 72 ms
70,480 KB
testcase_28 AC 75 ms
72,532 KB
testcase_29 AC 75 ms
72,524 KB
testcase_30 AC 72 ms
70,476 KB
testcase_31 AC 71 ms
70,476 KB
testcase_32 AC 158 ms
76,328 KB
testcase_33 AC 182 ms
76,328 KB
testcase_34 AC 150 ms
76,328 KB
testcase_35 AC 100 ms
76,328 KB
testcase_36 AC 38 ms
53,396 KB
testcase_37 AC 38 ms
53,396 KB
testcase_38 AC 90 ms
75,824 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
N, D = map(int, input().split())
a = []
b = []
t = []
for i in range(N):
  p, q = map(int, input().split())
  if p <= q: a.append((p, q, i))
  else: b.append((p, q, i))
  t.append((p, q))

s = set()

if len(a) >= 1:
  a.sort(key = lambda x: (x[0], -x[1]))
  s.add(a[0][2])

if len(a) >= 2:
  a.sort(key = lambda x: (x[0], -x[1]))
  s.add(a[1][2])

if len(a) >= 1:
  a.sort(key = lambda x: (-x[1], x[0]))
  s.add(a[0][2])

if len(a) >= 2:
  a.sort(key = lambda x: (-x[1], x[0]))
  s.add(a[1][2])

if len(b) >= 1:
  b.sort(key = lambda x: -x[1])
  s.add(b[0][2])

if len(b) >= 2:
  b.sort(key = lambda x: -x[1])
  s.add(b[1][2])

if len(b) >= 1:
  b.sort(key = lambda x: (x[0], -x[1]))
  s.add(b[0][2])

if len(b) >= 2:
  b.sort(key = lambda x: (x[0], -x[1]))
  s.add(b[1][2])

res = -10 ** 18
for i in s:
  for j in s:
    if i == j: continue
    tt = 0
    tres = 0
    for k in range(D):
      if k & 1:
        tt -= t[i][0]
        tres = min(tres, tt)
        tt += t[i][1]
      else:
        tt -= t[j][0]
        tres = min(tres, tt)
        tt += t[j][1]
    res = max(res, tres)
inf = -10 ** 9
def check(x):
  dp = [0] * N
  mxl = [inf] * (N + 1)
  mxr = [inf] * (N + 1)
  for _ in range(D):
    for i in range(N): mxl[i + 1] = max(mxl[i], dp[i])
    for i in range(N, 0, -1): mxr[i - 1] = max(mxr[i], dp[i - 1])
    for i in range(N):
      dp[i] = max(mxl[i], mxr[i + 1])
      if dp[i] - t[i][0] < x: dp[i] = inf
      else: dp[i] += t[i][1] - t[i][0]
    #print(mxl, mxr, dp)
  return max(dp) >= x

ok = res
ng = 0
while ng - ok > 1:
  m = (ok + ng) // 2
  if check(m): ok = m
  else: ng = m
res = max(res, ok)
print(res)
0