結果

問題 No.156 キャンディー・ボックス
ユーザー tsunabittsunabit
提出日時 2018-05-07 18:41:27
言語 Java21
(openjdk 21)
結果
AC  
実行時間 137 ms / 2,000 ms
コード長 2,563 bytes
コンパイル時間 5,183 ms
コンパイル使用メモリ 79,132 KB
実行使用メモリ 56,000 KB
最終ジャッジ日時 2023-09-19 03:42:02
合計ジャッジ時間 11,195 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 133 ms
55,872 KB
testcase_01 AC 133 ms
56,000 KB
testcase_02 AC 133 ms
55,508 KB
testcase_03 AC 134 ms
55,600 KB
testcase_04 AC 133 ms
55,544 KB
testcase_05 AC 134 ms
55,560 KB
testcase_06 AC 133 ms
55,384 KB
testcase_07 AC 135 ms
55,504 KB
testcase_08 AC 137 ms
55,352 KB
testcase_09 AC 133 ms
55,564 KB
testcase_10 AC 135 ms
55,644 KB
testcase_11 AC 137 ms
55,600 KB
testcase_12 AC 133 ms
55,512 KB
testcase_13 AC 135 ms
55,720 KB
testcase_14 AC 133 ms
55,364 KB
testcase_15 AC 132 ms
55,704 KB
testcase_16 AC 131 ms
55,788 KB
testcase_17 AC 131 ms
55,524 KB
testcase_18 AC 132 ms
55,984 KB
testcase_19 AC 130 ms
55,708 KB
testcase_20 AC 134 ms
55,744 KB
testcase_21 AC 134 ms
55,640 KB
testcase_22 AC 134 ms
55,388 KB
testcase_23 AC 133 ms
55,668 KB
testcase_24 AC 135 ms
55,744 KB
testcase_25 AC 133 ms
55,528 KB
testcase_26 AC 132 ms
55,860 KB
testcase_27 AC 130 ms
55,644 KB
testcase_28 AC 131 ms
55,668 KB
testcase_29 AC 130 ms
55,988 KB
testcase_30 AC 131 ms
55,596 KB
testcase_31 AC 129 ms
55,696 KB
testcase_32 AC 134 ms
55,692 KB
testcase_33 AC 135 ms
55,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
import java.util.stream.Stream;
import java.util.Arrays;

// ***問題文***
// キャンディーが入っている箱がN個ある。
// i番目の箱にはCi個のキャンディーが入っている。
// A君は、その時の最もキャンディーの少ない箱から1つキャンディーを取っていく。
// これを合計M個のキャンディーを取り終えるまで繰り返す。
// M個のキャンディーを取り出した時に、空になった箱の数はいくつか?
// ***入力***
// N M
// C1 C2 … CN
// 1≤N≤10
// 1≤M≤1000000
// 1≤Ci≤100000
// Mは最初のキャンディーの総数以下の数字が与えられる。
// ***出力***
// M個のキャンディーを取ったあとに空になった箱の数を1行で答えよ。
// 最後に改行を忘れずに。

public class No156 {
    public static void main(String[] args) {
        // 標準入力から読み込む際に、Scannerオブジェクトを使う。
        Scanner sc = new Scanner(System.in);
        // int n = sc.nextInt();
        // int m = sc.nextInt();
        // 2行目をnextLineで読み込むため、数値もnextLineで読み込む
        // int n = Integer.parseInt(sc.nextLine());
        // 新しいstreamを作成し、各要素をintに変換
        // int[] x = Stream.of(sc.nextLine().split(" " , 0)).mapToInt(Integer::parseInt).toArray();
        // int f = Integer.parseInt(sc.next().replace(".", ""));
        // int s = Integer.parseInt(sc.next().replace(".", ""));
        int[] nm = Stream.of(sc.nextLine().split(" " , 0)).mapToInt(Integer::parseInt).toArray();
        int[] c = Stream.of(sc.nextLine().split(" " , 0)).mapToInt(Integer::parseInt).toArray();
        // 配列をsort
        Arrays.sort(c);
        int total = 0;
        int count = 0;
        for(int i = 0; i < nm[0]; i++) {
            total += c[i];
            if(total > nm[1]) {
                count = i;
                break;
            }else if(total == nm[1]) {
                count = i + 1;
                break;
            }
        }
        System.out.println(count);
        // ------------------------------------------------------------
        // System.out.println("n = " + f);
        // System.out.println("n = " + s);
        // System.out.println("n = " + fa.length);
        // for(int i = 0; i < f.length; i++) {
        //     System.out.println("[" + i + "] = " + f[i]);
        // }
        // for(int a: x) {
        //     System.out.println("x = " + x);
        // }
    }
}
0