結果

問題 No.156 キャンディー・ボックス
ユーザー ayaaya
提出日時 2019-07-30 16:11:05
言語 PHP
(8.3.4)
結果
WA  
実行時間 -
コード長 1,037 bytes
コンパイル時間 1,070 ms
コンパイル使用メモリ 18,544 KB
実行使用メモリ 19,008 KB
最終ジャッジ日時 2023-09-18 07:14:24
合計ジャッジ時間 2,947 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 17 ms
18,704 KB
testcase_02 WA -
testcase_03 AC 16 ms
18,824 KB
testcase_04 AC 16 ms
18,860 KB
testcase_05 WA -
testcase_06 AC 16 ms
18,908 KB
testcase_07 AC 16 ms
18,876 KB
testcase_08 AC 17 ms
18,892 KB
testcase_09 AC 16 ms
18,724 KB
testcase_10 AC 16 ms
18,868 KB
testcase_11 AC 16 ms
18,908 KB
testcase_12 AC 16 ms
18,832 KB
testcase_13 AC 16 ms
18,892 KB
testcase_14 AC 15 ms
18,908 KB
testcase_15 AC 16 ms
18,856 KB
testcase_16 AC 16 ms
18,848 KB
testcase_17 AC 16 ms
18,904 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 16 ms
18,704 KB
testcase_26 AC 16 ms
18,900 KB
testcase_27 AC 16 ms
18,844 KB
testcase_28 AC 16 ms
18,840 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 16 ms
18,872 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?php
/*
No.156 キャンディー・ボックス
問題文
キャンディーが入っている箱がN個ある。
i番目の箱にはCi個のキャンディーが入っている。
A君は、その時の最もキャンディーの少ない箱から1つキャンディーを取っていく。
これを合計M個のキャンディーを取り終えるまで繰り返す。

M個のキャンディーを取り出した時に、空になった箱の数はいくつか?

入力
N M
C1 C2 … CN
1≤N≤10
1≤M≤1000000
1≤Ci≤100000
Mは最初のキャンディーの総数以下の数字が与えられる。

出力
M個のキャンディーを取ったあとに空になった箱の数を1行で答えよ。
*/
$input=explode(" ",(trim(fgets(STDIN))));
$wantCandyNum=$input[1];
$CandyBoxies=explode(" ",(trim(fgets(STDIN))));
sort($CandyBoxies);
$ans;
foreach($CandyBoxies as $key =>$value){
  if($value<$wantCandyNum){
    $wantCandyNum-=$value;
  }else if($value>=$wantCandyNum){
    $ans=$key+1;
    break;
  }
}
echo $ans;
?>
0