結果

問題 No.617 Nafmo、買い出しに行く
ユーザー 夕叢霧香(ゆうむらきりか)夕叢霧香(ゆうむらきりか)
提出日時 2017-12-17 01:19:05
言語 Java21
(openjdk 21)
結果
AC  
実行時間 165 ms / 2,000 ms
コード長 1,841 bytes
コンパイル時間 2,480 ms
コンパイル使用メモリ 77,996 KB
実行使用メモリ 40,100 KB
最終ジャッジ日時 2024-05-08 17:16:15
合計ジャッジ時間 5,667 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
36,956 KB
testcase_01 AC 54 ms
37,360 KB
testcase_02 AC 55 ms
37,028 KB
testcase_03 AC 76 ms
38,124 KB
testcase_04 AC 54 ms
37,208 KB
testcase_05 AC 80 ms
37,992 KB
testcase_06 AC 153 ms
38,016 KB
testcase_07 AC 155 ms
38,232 KB
testcase_08 AC 53 ms
37,020 KB
testcase_09 AC 55 ms
37,020 KB
testcase_10 AC 151 ms
37,920 KB
testcase_11 AC 153 ms
38,196 KB
testcase_12 AC 141 ms
38,016 KB
testcase_13 AC 157 ms
40,100 KB
testcase_14 AC 142 ms
38,108 KB
testcase_15 AC 164 ms
37,920 KB
testcase_16 AC 141 ms
38,244 KB
testcase_17 AC 165 ms
37,968 KB
testcase_18 AC 55 ms
36,852 KB
testcase_19 AC 54 ms
37,208 KB
testcase_20 AC 54 ms
37,336 KB
testcase_21 AC 53 ms
37,028 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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


class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        int n=sc.nextInt();
        int k=sc.nextInt();
        int[]a=new int[n];
        for(int i=0;i<n;++i)a[i]=sc.nextInt();
        int ans=0;
        for(int i=0;i<1<<n;++i){
            int t=0;
            for(int j=0;j<n;++j)
                if((i&1<<j)!=0)
                    t+=a[j];
            if(t<=k)ans=Math.max(ans,t);
        }
        out.println(ans);
        out.close();
    }
    // http://codeforces.com/blog/entry/7018
    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;
    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;
        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}
0