結果

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

ソースコード

diff #

#include <stdio.h>

void main(void){
	int n = 0,m = 0;
	scanf("%d",&n);
	scanf("%d",&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 = i ; 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++){
		m -= candyBox[i];
		if(m >= 0){
			nullBox++;
		}else{
			break;
		}
	}
	printf("%d",nullBox);
}
0