結果

問題 No.1676 Coin Trade (Single)
ユーザー ygd.
提出日時 2021-09-12 18:22:21
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 696 bytes
コンパイル時間 176 ms
コンパイル使用メモリ 82,272 KB
実行使用メモリ 92,436 KB
最終ジャッジ日時 2024-06-24 09:33:29
合計ジャッジ時間 4,542 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16 WA * 19
権限があれば一括ダウンロードができます

ソースコード

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)

    dp = [0]*(N+1)
    for i in range(N):
        dp[i+1] = max(dp[i+1],dp[i]) #何もしない
        for pre in RG[i]:
            if A[pre] < A[i]: #前のほうが安いなら。
                dif = A[i] - A[pre]
                dp[i+1] = max(dp[i+1], dp[pre] + dif)
    #print(dp)
    ans = dp[N]
    print(ans)

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