結果
問題 |
No.617 Nafmo、買い出しに行く
|
ユーザー |
![]() |
提出日時 | 2019-11-14 14:48:34 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 147 ms / 2,000 ms |
コード長 | 630 bytes |
コンパイル時間 | 2,349 ms |
コンパイル使用メモリ | 74,224 KB |
実行使用メモリ | 41,468 KB |
最終ジャッジ日時 | 2024-09-21 21:24:54 |
合計ジャッジ時間 | 6,352 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 20 |
ソースコード
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; } }