結果

問題 No.617 Nafmo、買い出しに行く
ユーザー tsunabittsunabit
提出日時 2019-07-18 22:29:23
言語 Java21
(openjdk 21)
結果
AC  
実行時間 227 ms / 2,000 ms
コード長 547 bytes
コンパイル時間 4,204 ms
コンパイル使用メモリ 73,360 KB
実行使用メモリ 58,092 KB
最終ジャッジ日時 2023-08-26 20:35:43
合計ジャッジ時間 9,336 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 112 ms
55,976 KB
testcase_01 AC 108 ms
55,824 KB
testcase_02 AC 113 ms
55,904 KB
testcase_03 AC 124 ms
55,628 KB
testcase_04 AC 111 ms
56,392 KB
testcase_05 AC 132 ms
55,816 KB
testcase_06 AC 225 ms
58,092 KB
testcase_07 AC 222 ms
55,968 KB
testcase_08 AC 110 ms
56,128 KB
testcase_09 AC 110 ms
55,864 KB
testcase_10 AC 219 ms
56,100 KB
testcase_11 AC 219 ms
56,148 KB
testcase_12 AC 214 ms
56,128 KB
testcase_13 AC 214 ms
55,972 KB
testcase_14 AC 224 ms
55,628 KB
testcase_15 AC 224 ms
55,572 KB
testcase_16 AC 221 ms
56,472 KB
testcase_17 AC 227 ms
55,876 KB
testcase_18 AC 113 ms
56,016 KB
testcase_19 AC 115 ms
56,016 KB
testcase_20 AC 114 ms
55,808 KB
testcase_21 AC 112 ms
55,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;
import java.math.*;

public class No617 {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt(), k = sc.nextInt();
    	int[] a = new int[n];
    	int max = 0;
    	for(int i = 0; i < n; i++) a[i] = sc.nextInt();
    	for(int i = 0; i < Math.pow(2, n); i++) {
    		int ans = 0;
    		for(int j = 0; j < n; j++) {
    			if((1 & i>>j) == 1) ans += a[j];
    		}
    		if(max < ans && ans <= k) max = ans;
    	}
    	System.out.println(max);
    }
}
0