結果

問題 No.156 キャンディー・ボックス
ユーザー tsunabittsunabit
提出日時 2018-05-07 18:38:07
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,514 bytes
コンパイル時間 3,775 ms
コンパイル使用メモリ 76,448 KB
実行使用メモリ 57,744 KB
最終ジャッジ日時 2023-09-10 10:55:52
合計ジャッジ時間 10,446 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 128 ms
56,060 KB
testcase_03 AC 126 ms
56,220 KB
testcase_04 AC 125 ms
55,944 KB
testcase_05 WA -
testcase_06 AC 129 ms
55,912 KB
testcase_07 AC 126 ms
56,032 KB
testcase_08 AC 128 ms
55,832 KB
testcase_09 AC 129 ms
56,092 KB
testcase_10 AC 128 ms
55,720 KB
testcase_11 AC 128 ms
55,876 KB
testcase_12 AC 124 ms
55,696 KB
testcase_13 AC 125 ms
56,000 KB
testcase_14 AC 126 ms
55,504 KB
testcase_15 AC 127 ms
55,864 KB
testcase_16 AC 126 ms
54,460 KB
testcase_17 AC 125 ms
55,692 KB
testcase_18 WA -
testcase_19 AC 126 ms
56,088 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 127 ms
55,932 KB
testcase_24 AC 129 ms
53,884 KB
testcase_25 AC 127 ms
55,924 KB
testcase_26 AC 126 ms
55,872 KB
testcase_27 AC 125 ms
55,812 KB
testcase_28 WA -
testcase_29 AC 125 ms
55,472 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 130 ms
55,792 KB
testcase_33 AC 128 ms
55,548 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();
        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