結果

問題 No.156 キャンディー・ボックス
ユーザー sasa
提出日時 2025-03-14 17:40:12
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 742 bytes
コンパイル時間 493 ms
コンパイル使用メモリ 28,288 KB
実行使用メモリ 14,908 KB
最終ジャッジ日時 2025-03-14 17:40:17
合計ジャッジ時間 4,886 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 2
other AC * 17 WA * 9 TLE * 1 -- * 3
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:6:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    6 |         scanf("%d%d",&box,&retrieve);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
main.cpp:10:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   10 |                 scanf("%d",&candy[i]);
      |                 ~~~~~^~~~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>

int main(){
	// 箱の数・飴を受け取る数
	int box, retrieve;
	scanf("%d%d",&box,&retrieve);
	// 箱ごとの飴の数
	int candy[box];
	for(int i = 0;i < box;i ++){
		scanf("%d",&candy[i]);
	}
	
	
	// 飴を受け取るループ
	while(retrieve > 0){
		// 飴の最小の数
		int min = 100001;
		// 飴の最小の要素数
		int element = 0;
		// 飴の最小数と要素数の特定
		for(int j = 0;j < box;j ++){
			if(min > candy[j] && candy[j] != 0){
				min = candy[j];
				element = j;
			}
		}
		retrieve -= candy[element];
		candy[element] -= candy[element];
	}
	// 飴が0個の箱を数える
	int count = 0;
	for(int i = 0;i < box;i ++){
		if(candy[i] == 0){
			count++;
		}
	}
	printf("%d",count);
}
0