結果

問題 No.1522 Unfairness
ユーザー tentententen
提出日時 2024-01-11 11:48:08
言語 Java21
(openjdk 21)
結果
AC  
実行時間 790 ms / 2,000 ms
コード長 2,233 bytes
コンパイル時間 2,711 ms
コンパイル使用メモリ 84,428 KB
実行使用メモリ 89,768 KB
最終ジャッジ日時 2024-01-11 11:48:21
合計ジャッジ時間 11,160 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
54,008 KB
testcase_01 AC 52 ms
53,996 KB
testcase_02 AC 53 ms
53,996 KB
testcase_03 AC 170 ms
63,968 KB
testcase_04 AC 100 ms
58,084 KB
testcase_05 AC 93 ms
55,548 KB
testcase_06 AC 89 ms
55,392 KB
testcase_07 AC 245 ms
69,220 KB
testcase_08 AC 252 ms
68,608 KB
testcase_09 AC 86 ms
55,396 KB
testcase_10 AC 125 ms
61,184 KB
testcase_11 AC 105 ms
58,104 KB
testcase_12 AC 139 ms
59,600 KB
testcase_13 AC 361 ms
80,992 KB
testcase_14 AC 89 ms
55,272 KB
testcase_15 AC 785 ms
89,632 KB
testcase_16 AC 735 ms
89,712 KB
testcase_17 AC 774 ms
89,644 KB
testcase_18 AC 790 ms
89,604 KB
testcase_19 AC 761 ms
89,768 KB
testcase_20 AC 302 ms
87,668 KB
testcase_21 AC 53 ms
54,112 KB
testcase_22 AC 53 ms
54,104 KB
testcase_23 AC 54 ms
53,996 KB
testcase_24 AC 55 ms
52,040 KB
testcase_25 AC 54 ms
53,996 KB
testcase_26 AC 54 ms
53,996 KB
testcase_27 AC 52 ms
53,992 KB
testcase_28 AC 53 ms
54,100 KB
testcase_29 AC 54 ms
53,992 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static int[] values;
    static int[][] dp;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int m = sc.nextInt();
        values = new int[n];
        for (int i = 0; i < n; i++) {
            values[i] = sc.nextInt();
        }
        Arrays.sort(values);
        dp = new int[n][m + 1];
        for (int[] arr : dp) {
            Arrays.fill(arr, -1); 
        }
        System.out.println(dfw(n - 1, m));
    }
    
    static int dfw(int idx, int v) {
        if (idx <= 0) {
            return 0;
        }
        if (dp[idx][v] < 0) {
            dp[idx][v] = dfw(idx - 1, v);
            for (int i = idx - 1; i >= 0 && values[idx] - values[i] <= v; i--) {
                dp[idx][v] = Math.max(dp[idx][v], dfw(i - 1, v - (values[idx] - values[i])) + values[idx]);
            }
        }
        return dp[idx][v];
    }
}
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0