結果

問題 No.914 Omiyage
ユーザー ks2mks2m
提出日時 2019-10-25 21:29:18
言語 Java21
(openjdk 21)
結果
AC  
実行時間 56 ms / 2,000 ms
コード長 970 bytes
コンパイル時間 1,986 ms
コンパイル使用メモリ 77,284 KB
実行使用メモリ 53,364 KB
最終ジャッジ日時 2023-10-24 21:10:23
合計ジャッジ時間 4,036 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
52,716 KB
testcase_01 AC 55 ms
52,696 KB
testcase_02 AC 54 ms
51,304 KB
testcase_03 AC 56 ms
52,480 KB
testcase_04 AC 55 ms
53,352 KB
testcase_05 AC 54 ms
53,348 KB
testcase_06 AC 54 ms
53,352 KB
testcase_07 AC 54 ms
53,344 KB
testcase_08 AC 55 ms
53,344 KB
testcase_09 AC 53 ms
53,364 KB
testcase_10 AC 54 ms
53,352 KB
testcase_11 AC 54 ms
52,444 KB
testcase_12 AC 55 ms
53,352 KB
testcase_13 AC 55 ms
53,348 KB
testcase_14 AC 55 ms
53,352 KB
testcase_15 AC 54 ms
53,352 KB
testcase_16 AC 54 ms
53,348 KB
testcase_17 AC 54 ms
53,344 KB
testcase_18 AC 54 ms
53,356 KB
testcase_19 AC 54 ms
53,344 KB
testcase_20 AC 54 ms
53,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int m = Integer.parseInt(sa[1]);
		int k = Integer.parseInt(sa[2]);
		int[][] a = new int[n][m];
		for (int i = 0; i < n; i++) {
			sa = br.readLine().split(" ");
			for (int j = 0; j < m; j++) {
				a[i][j] = Integer.parseInt(sa[j]);
			}
		}
		br.close();

		boolean[][] b = new boolean[n + 1][k + 1];
		b[0][k] = true;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j <= k; j++) {
				if (b[i][j]) {
					for (int j2 = 0; j2 < m; j2++) {
						if (j >= a[i][j2]) {
							b[i + 1][j - a[i][j2]] = true;
						}
					}
				}
			}
		}
		for (int j = 0; j <= k; j++) {
			if (b[n][j]) {
				System.out.println(j);
				return;
			}
		}
		System.out.println(-1);
	}
}
0