結果

問題 No.1454 ツブ消ししとるなEasy
ユーザー pengin_2000pengin_2000
提出日時 2021-07-11 15:14:16
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 1,320 bytes
コンパイル時間 658 ms
コンパイル使用メモリ 29,196 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-14 20:11:50
合計ジャッジ時間 2,027 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 20 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 19 ms
4,376 KB
testcase_08 AC 19 ms
4,376 KB
testcase_09 AC 19 ms
4,380 KB
testcase_10 AC 0 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 0 ms
4,380 KB
testcase_15 AC 0 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 0 ms
4,376 KB
testcase_19 AC 0 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
long long int h[100005], l;
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];
}
int main()
{
	int n, m, x, y;
	scanf("%d %d %d %d", &n, &m, &x, &y);
	int i;
	long long int a[100005];
	for (i = 0; i < n; i++)
		scanf("%lld", &a[i]);
	l = 0;
	for (i = 0; i < n; i++)
		push(a[i]);
	for (i = 0; i < n; i++)
		a[i] = pop();
	a[n] = -1;
	long long int ans = 0;
	for (i = 0; i<m && a[i]>y; i++)
		ans += a[i];
	if (a[m] >= x)
		printf("Handicapped\n");
	else
		printf("%lld\n", ans);
	return 0;
}
0