結果

問題 No.5 数字のブロック
ユーザー A63295
提出日時 2015-12-19 13:57:50
言語 C90
(gcc 12.3.0)
結果
AC  
実行時間 162 ms / 5,000 ms
コード長 442 bytes
コンパイル時間 426 ms
コンパイル使用メモリ 21,632 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-18 07:58:45
合計ジャッジ時間 2,350 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます
コンパイルメッセージ
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:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    8 |         scanf("%d",&W[i]);
      |         ^~~~~~~~~~~~~~~~~

ソースコード

diff #

#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 < N; i++){
	goukei += W[i];
	count++;
}
if(goukei > L){
	count--;
}
printf ("%d",count);
return 0;
}
0