結果

問題 No.1715 Dinner 2
ユーザー tamatotamato
提出日時 2021-10-22 22:18:30
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,444 bytes
コンパイル時間 382 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 76,184 KB
最終ジャッジ日時 2024-09-23 05:54:49
合計ジャッジ時間 4,441 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 35 WA * 3
権限があれば一括ダウンロードができます

ソースコード

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):
            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:
                PP = []
                for i in best_i:
                    PP.append((P[i], i))
                PP.sort(key=lambda x: x[0])
                if (D - d) & 1:
                    prev = PP[0][1]
                else:
                    prev = PP[1][1]
            else:
                prev = best_i[0]
            cur = best
        if flg == 0:
            ng = mid
        else:
            ok = mid
        mid = (ok + ng) // 2
    print(ok)


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