結果

問題 No.1708 Quality of Contest
ユーザー pengin_2000pengin_2000
提出日時 2022-08-22 23:38:04
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 101 ms / 2,000 ms
コード長 1,716 bytes
コンパイル時間 249 ms
コンパイル使用メモリ 31,872 KB
実行使用メモリ 11,212 KB
最終ジャッジ日時 2024-04-18 13:32:39
合計ジャッジ時間 3,898 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 78 ms
11,212 KB
testcase_10 AC 97 ms
11,176 KB
testcase_11 AC 95 ms
10,112 KB
testcase_12 AC 95 ms
10,368 KB
testcase_13 AC 93 ms
9,984 KB
testcase_14 AC 96 ms
10,496 KB
testcase_15 AC 95 ms
11,120 KB
testcase_16 AC 101 ms
11,136 KB
testcase_17 AC 100 ms
10,496 KB
testcase_18 AC 94 ms
10,624 KB
testcase_19 AC 98 ms
10,752 KB
testcase_20 AC 96 ms
10,496 KB
testcase_21 AC 98 ms
10,624 KB
testcase_22 AC 96 ms
10,496 KB
testcase_23 AC 100 ms
11,136 KB
testcase_24 AC 95 ms
9,728 KB
testcase_25 AC 92 ms
9,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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