結果

問題 No.156 キャンディー・ボックス
ユーザー Maeda
提出日時 2025-03-10 13:48:01
言語 C
(gcc 13.3.0)
結果
RE  
実行時間 -
コード長 489 bytes
コンパイル時間 197 ms
コンパイル使用メモリ 25,600 KB
実行使用メモリ 7,328 KB
最終ジャッジ日時 2025-03-10 13:48:08
合計ジャッジ時間 5,823 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample RE * 4
other RE * 30
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:8:25: warning: format ‘%d’ expects argument of type ‘int *’, but argument 2 has type ‘int’ [-Wformat=]
    8 |                 scanf("%d",candyBox[i]);
      |                        ~^  ~~~~~~~~~~~
      |                         |          |
      |                         int *      int
main.c:5:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    5 |         scanf("%d %d",&n,&m);
      |         ^~~~~~~~~~~~~~~~~~~~
main.c:8:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    8 |                 scanf("%d",candyBox[i]);
      |                 ^~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>

void main(void){
	int n,m;
	scanf("%d %d",&n,&m);
	int candyBox[n];
	for(int i = 0 ; i < n ; i ++){
		scanf("%d",candyBox[i]);
	}
	
	for(int i = 0 ; i < n ; i++){
		for(int j = 0 ; j < n ; j++){
			if(candyBox[i] < candyBox[j]){
				int num = candyBox[i];
				candyBox[i] = candyBox[j];
				candyBox[j] = num;
			}
		}
	}
	int nullBox = 0;
	for(int i = 0 ; i < n ; i++){
		n -= candyBox[i];
		if(n >= 0){
			nullBox++;
		}else{
			break;
		}
	}
	printf("%d",nullBox);
}
0