結果

問題 No.2693 Sword
ユーザー tentententen
提出日時 2024-03-25 13:36:22
言語 Java21
(openjdk 21)
結果
AC  
実行時間 114 ms / 2,000 ms
コード長 2,293 bytes
コンパイル時間 2,645 ms
コンパイル使用メモリ 78,800 KB
実行使用メモリ 64,556 KB
最終ジャッジ日時 2024-03-25 13:36:29
合計ジャッジ時間 6,151 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
53,988 KB
testcase_01 AC 50 ms
53,996 KB
testcase_02 AC 47 ms
53,988 KB
testcase_03 AC 49 ms
53,992 KB
testcase_04 AC 50 ms
53,980 KB
testcase_05 AC 48 ms
53,940 KB
testcase_06 AC 48 ms
53,980 KB
testcase_07 AC 48 ms
53,988 KB
testcase_08 AC 48 ms
53,996 KB
testcase_09 AC 102 ms
57,736 KB
testcase_10 AC 52 ms
53,988 KB
testcase_11 AC 77 ms
54,756 KB
testcase_12 AC 50 ms
53,992 KB
testcase_13 AC 86 ms
54,236 KB
testcase_14 AC 95 ms
53,976 KB
testcase_15 AC 102 ms
55,644 KB
testcase_16 AC 109 ms
55,908 KB
testcase_17 AC 114 ms
58,004 KB
testcase_18 AC 86 ms
55,892 KB
testcase_19 AC 69 ms
55,140 KB
testcase_20 AC 74 ms
54,888 KB
testcase_21 AC 95 ms
56,064 KB
testcase_22 AC 90 ms
57,740 KB
testcase_23 AC 73 ms
54,632 KB
testcase_24 AC 58 ms
53,972 KB
testcase_25 AC 51 ms
53,996 KB
testcase_26 AC 51 ms
53,976 KB
testcase_27 AC 51 ms
53,992 KB
testcase_28 AC 50 ms
53,972 KB
testcase_29 AC 53 ms
54,008 KB
testcase_30 AC 52 ms
53,976 KB
testcase_31 AC 51 ms
53,988 KB
testcase_32 AC 91 ms
64,556 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;

public class Main {
    static final long MAX = 1000000000000000000L;
    static long[][] dp;
    static long p;
    static boolean[] isDouble;
    static int[] values;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        p = sc.nextLong();
        int k = sc.nextInt();
        isDouble = new boolean[n];
        values = new int[n];
        for (int i = 0; i < n; i++) {
            isDouble[i] = sc.nextInt() == 2;
            values[i] = sc.nextInt();
        }
        dp = new long[n][k + 1];
        for (long[] arr : dp) {
            Arrays.fill(arr, Long.MIN_VALUE);
        }
        long ans = dfw(n - 1, k);
        System.out.println(ans > MAX ? -1 : ans);
    }
    
    static long dfw(int idx, int v) {
        if (idx + 1 < v) {
            return Long.MIN_VALUE / 2;
        }
        if (v == 0) {
            return p;
        }
        if (dp[idx][v] == Long.MIN_VALUE) {
            dp[idx][v] = Math.max(dfw(idx - 1, v), func(isDouble[idx], values[idx], dfw(idx - 1, v - 1)));
        }
        return dp[idx][v];
    }
    
    static long func(boolean isD, int v, long current) {
        if (isD) {
            return Math.min(MAX + 1, current * 2);
        } else {
            return Math.min(MAX + 1, current + v);
        }
    }
}
class Scanner {
    BufferedReader br;
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
        } catch (Exception e) {
            
        }
    }
    
    public int nextInt() {
        return Integer.parseInt(next());
    }
    
    public long nextLong() {
        return Long.parseLong(next());
    }
    
    public double nextDouble() {
        return Double.parseDouble(next());
    }
    
    public String next() {
        try {
            while (!st.hasMoreTokens()) {
                st = new StringTokenizer(br.readLine());
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            return st.nextToken();
        }
    }
    
}
0