結果

問題 No.5 数字のブロック
ユーザー ふっぴー
提出日時 2017-03-30 16:29:12
言語 C90
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 788 bytes
コンパイル時間 132 ms
コンパイル使用メモリ 23,680 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-07 03:01:10
合計ジャッジ時間 1,166 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 28 WA * 6
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:13:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   13 |         scanf("%d %d",&l,&n);
      |         ^~~~~~~~~~~~~~~~~~~~
main.c:17:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   17 |                 scanf("%d",&w[i]);
      |                 ^~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <stdlib.h>
#define INF 1000000000;

void Qsort(int x[], int left, int right);
void swap(int x[],int i,int j);

int main(void){
	int l,n;
	scanf("%d %d",&l,&n);
	int w[n];
	int i;
	for(i=0;i<n;i++){
		scanf("%d",&w[i]);
	}
	Qsort(w,0,n-1);
	i=0;
	while(l-w[i]>=0){
		l=l-w[i];
		i++;
	}
	printf("%d\n",i);
	return 0;
}

void Qsort(int x[], int left, int right){
	int i,j;
	int pivot;
	i=left;
	j=right;
	pivot=x[(left+right)/2];
	while(1){
		while(x[i]<pivot)
			i++;
		while(pivot<x[j])
			j--;
		if(i>=j)
			break;
		swap(x,i,j);
		i++;
		j--;
	}
	if(left<i-1)
		Qsort(x,left,i-1);
	if(j+1<right)
		Qsort(x,j+1,right);
}

void swap(int x[],int i,int j){
	int temp;
	temp=x[i];
	x[i]=x[j];
	x[j]=temp;
}
0