結果

問題 No.156 キャンディー・ボックス
ユーザー kachipankachipan
提出日時 2023-07-03 14:49:56
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,747 bytes
コンパイル時間 1,205 ms
コンパイル使用メモリ 29,156 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-24 11:27:31
合計ジャッジ時間 1,950 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 1 ms
4,376 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 1 ms
4,376 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
#include <string.h>

void QuickSort(int arr[], int start, int last);

int main()
{
	int candyBox = 0;
	int takeCandy = 0;
	int candy[10] = { 0 };
	int zero = 0;

	scanf("%d", &candyBox);
	scanf("%d", &takeCandy);

	for (int i = 0;i < candyBox;i++)
	{
		scanf("%d", &candy);
	}

	QuickSort(candy, 0, candyBox - 1);

	for (int i = 0;i < candyBox;i++)
	{
		takeCandy -= candy[i];
		if (takeCandy <= 0)
		{
			zero = i;
		}
	}

	if (zero = 0)
	{
		zero = candyBox;
	}

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

	return 0;
}

void QuickSort(int arr[], int start, int last)
{
	int i = start;
	int k = last;
	int standard = arr[start];		// 基準値

	// ソートを行う範囲が1以下の場合は抜ける
	if (start >= last)
	{
		return;
	}

	while (true)
	{
		// pivotより値が大きくなるまで要素番号が小さい順に配列を探索
		while (arr[i] < standard)
		{
			i++;
		}

		// pivotより値が小さくなるまで要素番号が大きい順に配列を探索
		while (arr[k] > standard)
		{
			k--;
		}

		// iがk以上になったら、基準の数値より小さい側と大きい側にわけられている
		if (i >= k)
		{
			break;
		}

		// ここまで来てたらarr[i]は基準値より大きく、arr[k]は基準値より小さい
		// ので値を交換する
		int tmp = arr[i];
		arr[i] = arr[k];
		arr[k] = tmp;

		// 探索を再開
		i++;
		k--;
	}

	// 基準値より小さい範囲に対して同じ処理を行う
	// arr[i]は基準値なので-1して渡す。
	QuickSort(arr, start, i - 1);

	// 基準値より大きい範囲に対して同じ処理を行う
	// arr[k]は基準値なので+1して渡す。
	QuickSort(arr, k + 1, last);
}
0