結果

問題 No.5 数字のブロック
ユーザー akakimidoriakakimidori
提出日時 2015-07-26 21:43:31
言語 C90
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 500 bytes
コンパイル時間 127 ms
コンパイル使用メモリ 21,504 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-08 14:16:21
合計ジャッジ時間 957 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 24 WA * 10
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:17:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   17 |         scanf("%d",&L);
      |         ^~~~~~~~~~~~~~
main.c:20:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   20 |         scanf("%d",&N);
      |         ^~~~~~~~~~~~~~
main.c:25:26: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   25 |         for(i=0;i<N;i++) scanf("%d",&W[i]);
      |                          ^~~~~~~~~~~~~~~~~

ソースコード

diff #

#include<stdio.h>
#include<stdlib.h>

int comp(const void *c1,const void *c2){

	int t1 = *(int *)c1;
	int t2 = *(int *)c2;

	if(t1<t2) return -1;
	if(t1==t2) return 0;
	return 1;
}

int main(void){

	int L;
	scanf("%d",&L);

	int N;
	scanf("%d",&N);

	int *W;
	W=(int *)malloc(sizeof(int)*N);
	int i;
	for(i=0;i<N;i++) scanf("%d",&W[i]);

	qsort(W,N,sizeof(int),comp);

	int count=0;
	i=0;
	int m=0;
	while(m+W[i]<=L){
		count++;
		m+=W[i];
		i++;
	}

	printf("%d\n",count);

	free(W);
	return 0;
}
0