結果

問題 No.1676 Coin Trade (Single)
ユーザー merlin
提出日時 2021-09-10 22:48:53
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 1,196 bytes
コンパイル時間 2,417 ms
コンパイル使用メモリ 76,776 KB
実行使用メモリ 50,348 KB
最終ジャッジ日時 2024-06-12 02:25:05
合計ジャッジ時間 8,932 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16 WA * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb=new StringBuilder();
        String s[]=bu.readLine().split(" ");
        int n=Integer.parseInt(s[0]),k=Integer.parseInt(s[1]);

        int i,b[]=new int[n];
        long dp[][]=new long[n][2],ans=0;
        for(i=0;i<n;i++)
        {
            s=bu.readLine().split(" ");
            int c=Integer.parseInt(s[0]),m=Integer.parseInt(s[1]);
            if(i>0)
            {
                dp[i][0]=dp[i-1][0];    //0 means no coin bought to store
                dp[i][1]=dp[i-1][0]-c;  //1 means coin bought to store
            }
            else dp[i][1]=-c;

            int j,x;
            s=bu.readLine().split(" ");
            for(j=0;j<m;j++)
            {
                x=Integer.parseInt(s[j])-1;
                dp[i][0]=Math.max(dp[x][1]+c,dp[i][0]);
            }

            ans=Math.max(ans,dp[i][0]);
            ans=Math.max(ans,dp[i][1]);
            //System.out.println(dp[i][0]+" "+dp[i][1]);
        }
        System.out.println(ans);
    }
}
0