結果

問題 No.2424 Josouzai
ユーザー pengin_2000pengin_2000
提出日時 2023-08-18 21:22:47
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 60 ms / 2,000 ms
コード長 1,309 bytes
コンパイル時間 1,163 ms
コンパイル使用メモリ 29,172 KB
実行使用メモリ 4,916 KB
最終ジャッジ日時 2023-08-18 21:22:52
合計ジャッジ時間 2,877 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 0 ms
4,380 KB
testcase_02 AC 0 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 17 ms
4,376 KB
testcase_05 AC 60 ms
4,916 KB
testcase_06 AC 58 ms
4,912 KB
testcase_07 AC 58 ms
4,876 KB
testcase_08 AC 59 ms
4,916 KB
testcase_09 AC 0 ms
4,380 KB
testcase_10 AC 12 ms
4,380 KB
testcase_11 AC 35 ms
4,612 KB
testcase_12 AC 25 ms
4,380 KB
testcase_13 AC 18 ms
4,376 KB
testcase_14 AC 31 ms
4,380 KB
testcase_15 AC 4 ms
4,380 KB
testcase_16 AC 52 ms
4,556 KB
testcase_17 AC 13 ms
4,380 KB
testcase_18 AC 16 ms
4,376 KB
testcase_19 AC 27 ms
4,388 KB
testcase_20 AC 53 ms
4,472 KB
testcase_21 AC 39 ms
4,380 KB
testcase_22 AC 17 ms
4,376 KB
testcase_23 AC 21 ms
4,380 KB
testcase_24 AC 10 ms
4,380 KB
testcase_25 AC 55 ms
4,684 KB
testcase_26 AC 39 ms
4,376 KB
testcase_27 AC 58 ms
4,828 KB
testcase_28 AC 49 ms
4,380 KB
testcase_29 AC 43 ms
4,380 KB
testcase_30 AC 10 ms
4,376 KB
testcase_31 AC 25 ms
4,380 KB
testcase_32 AC 56 ms
4,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
long long int h[200005], l;
long long int comp_h(long long int a, long long int b)
{
	if (h[a] > h[b])
		return 1;
	else
		return -1;
}
void swap_h(long long int a, long long int b)
{
	long long int f = h[a];
	h[a] = h[b];
	h[b] = f;
	return;
}
void push(long long int ne)
{
	h[l] = ne;
	long long int p = l;
	l++;
	for (; p > 0; p = (p - 1) / 2)
		if (comp_h((p - 1) / 2, p) > 0)
			swap_h((p - 1) / 2, p);
	return;
}
long long int pop()
{
	l--;
	swap_h(0, l);
	long long int p = 0;
	for (;;)
	{
		if (2 * p + 2 < l)
		{
			if (comp_h(2 * p + 1, 2 * p + 2) > 0)
			{
				if (comp_h(p, 2 * p + 2) > 0)
					swap_h(p, 2 * p + 2);
				p = 2 * p + 2;
			}
			else
			{
				if (comp_h(p, 2 * p + 1) > 0)
					swap_h(p, 2 * p + 1);
				p = 2 * p + 1;
			}
		}
		else if (2 * p + 1 < l)
		{
			if (comp_h(p, 2 * p + 1) > 0)
				swap_h(p, 2 * p + 1);
			p = 2 * p + 1;
		}
		else
			break;
	}
	return h[l];
}
long long int a[200005];
int main()
{
	long long int n, k;
	scanf("%lld %lld", &n, &k);
	long long int i;
	for (i = 0; i < n; i++)
		scanf("%d", &a[i]);
	l = 0;
	for (i = 0; i < n; i++)
		push(a[i]);
	for (i = 0; i < n; i++)
		a[i] = pop();
	long long int cnt = 0;
	for (i = 0; i < n; i++)
	{
		if (a[i] <= k)
		{
			cnt++;
			k -= a[i];
		}
	}
	printf("%lld %lld\n", cnt, k);
	return 0;
}
0