結果

問題 No.5 数字のブロック
ユーザー toto
提出日時 2025-03-26 14:51:18
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 556 bytes
コンパイル時間 256 ms
コンパイル使用メモリ 27,708 KB
実行使用メモリ 7,328 KB
最終ジャッジ日時 2025-03-26 14:51:21
合計ジャッジ時間 2,886 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 5 WA * 29
権限があれば一括ダウンロードができます
コンパイルメッセージ
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",&block,&box);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~
main.cpp:10:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   10 |                 scanf("%d",&tolerance[i]);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>

int main(){
	// ブロック数・箱数
	int block,box;
	scanf("%d%d",&block,&box);
	// 1つの箱にブロックが入る数
	int tolerance[box];
	for(int i = 0;i < box;i ++){
		scanf("%d",&tolerance[i]);
	}
	
	// ソート
	for(int i = 0;i < box;i ++){
		for(int j = 0;j < box;j ++){
			if(tolerance[i] > tolerance[j]){
				int tmp = tolerance[i];
				tolerance[i] = tolerance[j];
				tolerance[j] = tmp;
			}
		}
	}
	
	int now = 0;
	int count = 0;
	while(now < block){
		now += tolerance[count];
		count++;
	}
	printf("%d",count);
}
0