結果

問題 No.617 Nafmo、買い出しに行く
ユーザー htensaihtensai
提出日時 2019-11-14 14:48:34
言語 Java21
(openjdk 21)
結果
AC  
実行時間 143 ms / 2,000 ms
コード長 630 bytes
コンパイル時間 2,148 ms
コンパイル使用メモリ 80,348 KB
実行使用メモリ 57,604 KB
最終ジャッジ日時 2023-10-21 19:59:32
合計ジャッジ時間 6,067 ms
ジャッジサーバーID
(参考情報)
judge11 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 131 ms
57,452 KB
testcase_01 AC 133 ms
57,384 KB
testcase_02 AC 135 ms
57,292 KB
testcase_03 AC 138 ms
57,356 KB
testcase_04 AC 133 ms
57,588 KB
testcase_05 AC 138 ms
57,348 KB
testcase_06 AC 142 ms
57,604 KB
testcase_07 AC 141 ms
57,324 KB
testcase_08 AC 132 ms
57,472 KB
testcase_09 AC 130 ms
57,356 KB
testcase_10 AC 142 ms
57,544 KB
testcase_11 AC 143 ms
57,344 KB
testcase_12 AC 142 ms
57,396 KB
testcase_13 AC 143 ms
57,328 KB
testcase_14 AC 143 ms
55,476 KB
testcase_15 AC 136 ms
57,364 KB
testcase_16 AC 135 ms
57,572 KB
testcase_17 AC 136 ms
57,568 KB
testcase_18 AC 133 ms
57,316 KB
testcase_19 AC 132 ms
57,424 KB
testcase_20 AC 135 ms
57,384 KB
testcase_21 AC 133 ms
57,596 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static int n;
    static int k;
    static int[] arr;
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		k = sc.nextInt();
		arr = new int[n];
		for (int i = 0; i < n; i++) {
		    arr[i] = sc.nextInt();
		}
		System.out.println(search(0, 0));
	}
	
	static int search(int idx, int weight) {
	    if (idx >= n) {
	        return weight;
	    }
	    int ans = weight;
	    if (weight + arr[idx] <= k) {
	        ans = search(idx + 1, weight + arr[idx]);
	    }
	    ans = Math.max(ans, search(idx + 1, weight));
	    return ans;
	}
}
0