結果
| 問題 |
No.617 Nafmo、買い出しに行く
|
| コンテスト | |
| ユーザー |
YamaKasa
|
| 提出日時 | 2018-06-06 22:27:51 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 259 ms / 2,000 ms |
| コード長 | 1,175 bytes |
| コンパイル時間 | 2,262 ms |
| コンパイル使用メモリ | 80,872 KB |
| 実行使用メモリ | 41,824 KB |
| 最終ジャッジ日時 | 2024-06-30 10:23:11 |
| 合計ジャッジ時間 | 6,857 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 20 |
ソースコード
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static int [] A;
public static int K;
public static int max = 0;
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int N = scan.nextInt();
K = scan.nextInt();
A = new int[N];
for(int i = 0; i < N; i++) {
A[i] = scan.nextInt();
}
scan.close();
int []S = new int[N];
Arrays.fill(S, 0);
rec(0, N, S);
System.out.println(max);
}
public static void rec(int k, int n, int[] S) {
if(k == n) {
solve(S);
return;
}
rec(k + 1, n, S);
S[k] = 1;
rec(k + 1,n, S);
S[k] = 0;
}
public static void solve(int[] S) {
//disp(S);
int sum = 0;
for(int i = 0; i < S.length; i++) {
if(S[i] == 1) {
sum += A[i];
}
if(sum > K) {
break;
}else if(sum == K) {
System.out.println(K);
System.exit(0);
}else {
if(max < sum) {
max = sum;
}
}
}
}
public static void disp(int []A) {
for(int i = 0; i < A.length - 1; i++) {
System.out.print(A[i] + ", ");
}
System.out.println(A[A.length -1]);
}
}
YamaKasa