結果

問題 No.914 Omiyage
ユーザー tentententen
提出日時 2022-08-12 15:23:07
言語 Java21
(openjdk 21)
結果
AC  
実行時間 94 ms / 2,000 ms
コード長 1,552 bytes
コンパイル時間 3,980 ms
コンパイル使用メモリ 78,096 KB
実行使用メモリ 55,388 KB
最終ジャッジ日時 2023-10-24 00:50:17
合計ジャッジ時間 7,455 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
55,124 KB
testcase_01 AC 90 ms
55,384 KB
testcase_02 AC 55 ms
51,648 KB
testcase_03 AC 94 ms
55,388 KB
testcase_04 AC 57 ms
53,488 KB
testcase_05 AC 55 ms
52,552 KB
testcase_06 AC 55 ms
52,588 KB
testcase_07 AC 54 ms
53,484 KB
testcase_08 AC 56 ms
53,472 KB
testcase_09 AC 55 ms
52,580 KB
testcase_10 AC 57 ms
53,432 KB
testcase_11 AC 54 ms
53,484 KB
testcase_12 AC 67 ms
54,056 KB
testcase_13 AC 75 ms
55,164 KB
testcase_14 AC 94 ms
54,840 KB
testcase_15 AC 56 ms
52,984 KB
testcase_16 AC 54 ms
52,564 KB
testcase_17 AC 82 ms
55,016 KB
testcase_18 AC 53 ms
52,584 KB
testcase_19 AC 53 ms
53,472 KB
testcase_20 AC 53 ms
52,564 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int m = sc.nextInt();
        int k = sc.nextInt();
        TreeSet<Integer> current = new TreeSet<>();
        current.add(0);
        for (int i = 0; i < n; i++) {
            TreeSet<Integer> next = new TreeSet<>();
            for (int j = 0; j < m; j++) {
                int x = sc.nextInt();
                for (int y : current) {
                    if (x + y <= k) {
                        next.add(x + y);
                    }
                }
            }
            current = next;
        }
        if (current.size() == 0) {
            System.out.println(-1);
        } else {
            System.out.println(k - current.last());
        }
    }
}

class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    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 String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0