結果

問題 No.1676 Coin Trade (Single)
ユーザー ygd.
提出日時 2021-09-12 19:23:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 177 ms / 2,000 ms
コード長 766 bytes
コンパイル時間 238 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 92,384 KB
最終ジャッジ日時 2024-06-24 10:47:11
合計ジャッジ時間 5,277 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.buffer.readline

def main():
    N,K = map(int,input().split())
    A = []; M = []
    RG = []
    for i in range(N):
        a,m = map(int,input().split())
        A.append(a)
        M.append(m)
        B = list(map(int,input().split()))
        B = [b-1 for b in B] #0index
        RG.append(B)
    #print(RG)
    dp = [0]*(N+1)
    for i in range(N):
        dp[i+1] = max(dp[i+1],dp[i]) #何もしない
        for pre in RG[i]:
            #if pre < i and A[pre] < A[i]: #前のほうが安いなら。
            dif = A[i] - A[pre]
            dp[i+1] = max(dp[i+1], dp[pre+1] + dif) #ここでpreのIndexはPre+1
        #print(dp)
    #print(dp)
    ans = dp[N]
    print(ans)

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