結果
| 問題 |
No.914 Omiyage
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-03-10 04:32:29 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 143 ms / 2,000 ms |
| コード長 | 767 bytes |
| コンパイル時間 | 2,112 ms |
| コンパイル使用メモリ | 77,892 KB |
| 実行使用メモリ | 54,428 KB |
| 最終ジャッジ日時 | 2024-11-15 23:03:33 |
| 合計ジャッジ時間 | 6,016 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 18 |
ソースコード
import java.util.ArrayList;
import java.util.Scanner;
class Main {
public static void main(String[] args) {
new Main().run();
}
void run() {
Scanner sc=new Scanner(System.in);
int N=sc.nextInt();
int M=sc.nextInt();
int K=sc.nextInt();
int[][] A=new int[N][M];
boolean[][] dp=new boolean[N+1][K+1];
for(int i=0;i<A.length;++i) {
for(int j=0;j<A[i].length;++j) {
A[i][j]=sc.nextInt();
}
}
dp[0][0]=true;
for(int i=0;i<N;++i) {
for(int cur=0;cur<=K;++cur) {
if(!dp[i][cur])continue;
for(int next=0;next<M;++next) {
if(cur+A[i][next]<=K)
dp[i+1][cur+A[i][next]]|=dp[i][cur];
}
}
}
int ans=-1;
for(int i=1;i<=K;++i)if(dp[N][i])ans=Math.max(ans, i);
System.out.println(ans==-1?-1:(K-ans));
}
}