結果

問題 No.5 数字のブロック
コンテスト
ユーザー A63295
提出日時 2015-12-19 13:50:10
言語 C90
(gcc 12.4.0)
コンパイル:
gcc-12 -O2 -std=c90 -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
WA  
実行時間 -
コード長 431 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 153 ms
コンパイル使用メモリ 30,148 KB
最終ジャッジ日時 2026-02-23 20:11:02
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 27 WA * 7
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:5:1: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    5 | scanf("%d%d", &L, &N);
      | ^~~~~~~~~~~~~~~~~~~~~
main.c:8:1: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    8 | scanf("%d",&W[i]);
      | ^~~~~~~~~~~~~~~~~

ソースコード

diff #
raw source code

#include <stdio.h>
int main(void){
int i, j, tmp, L, N;
int W[10000] = {};
scanf("%d%d", &L, &N);

for( i = 0; i < N; i++){
scanf("%d",&W[i]);
}
for( i = 0; i < N - 1; ++i){
	for ( j = i + 1; j < N; ++j){
		if ( W[i] > W[j]){
			tmp = W[i];
			W[i] = W[j];
			W[j] = tmp;
	
		} 
	}
}
int goukei = 0, count = 0;
for ( i = 0; goukei < L; i++){
	goukei += W[i];
	count++;
}
if(goukei > L){
	count--;
}
printf ("%d",count);
return 0;
}
0