結果
問題 | No.914 Omiyage |
ユーザー |
![]() |
提出日時 | 2019-10-25 21:29:18 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 59 ms / 2,000 ms |
コード長 | 970 bytes |
コンパイル時間 | 2,174 ms |
コンパイル使用メモリ | 77,676 KB |
実行使用メモリ | 50,400 KB |
最終ジャッジ日時 | 2024-09-24 16:23:32 |
合計ジャッジ時間 | 3,958 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 18 |
ソースコード
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);}}