結果
| 問題 | 
                            No.156 キャンディー・ボックス
                             | 
                    
| コンテスト | |
| ユーザー | 
                             sasa
                         | 
                    
| 提出日時 | 2025-03-14 17:30:16 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 712 bytes | 
| コンパイル時間 | 564 ms | 
| コンパイル使用メモリ | 28,160 KB | 
| 実行使用メモリ | 7,324 KB | 
| 最終ジャッジ日時 | 2025-03-14 17:30:19 | 
| 合計ジャッジ時間 | 2,744 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 26 WA * 4 | 
コンパイルメッセージ
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]);
      |                 ~~~~~^~~~~~~~~~~~~~~~
            
            ソースコード
#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]);
	}
	
	
	// 飴を受け取るループ
	for(int i = 0;i < retrieve;i ++){
		// 飴の最小の数
		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;
			}
		}
		candy[element] -= 1;
	}
	// 飴が0個の箱を数える
	int count = 0;
	for(int i = 0;i < box;i ++){
		if(candy[i] == 0){
			count++;
		}
	}
	printf("%d",count);
}
            
            
            
        
            
sasa