結果

問題 No.1708 Quality of Contest
ユーザー 👑 ygussanyygussany
提出日時 2021-10-15 21:34:24
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 151 ms / 2,000 ms
コード長 1,480 bytes
コンパイル時間 549 ms
コンパイル使用メモリ 30,488 KB
実行使用メモリ 6,620 KB
最終ジャッジ日時 2023-10-17 20:05:25
合計ジャッジ時間 4,037 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,584 KB
testcase_01 AC 2 ms
4,584 KB
testcase_02 AC 2 ms
4,584 KB
testcase_03 AC 3 ms
4,584 KB
testcase_04 AC 3 ms
4,584 KB
testcase_05 AC 4 ms
4,584 KB
testcase_06 AC 3 ms
4,584 KB
testcase_07 AC 3 ms
4,584 KB
testcase_08 AC 2 ms
4,584 KB
testcase_09 AC 70 ms
6,620 KB
testcase_10 AC 150 ms
6,620 KB
testcase_11 AC 137 ms
6,620 KB
testcase_12 AC 133 ms
6,620 KB
testcase_13 AC 142 ms
6,620 KB
testcase_14 AC 130 ms
6,620 KB
testcase_15 AC 122 ms
6,620 KB
testcase_16 AC 126 ms
6,620 KB
testcase_17 AC 134 ms
6,620 KB
testcase_18 AC 134 ms
6,620 KB
testcase_19 AC 131 ms
6,620 KB
testcase_20 AC 135 ms
6,620 KB
testcase_21 AC 125 ms
6,620 KB
testcase_22 AC 124 ms
6,620 KB
testcase_23 AC 124 ms
6,620 KB
testcase_24 AC 147 ms
6,620 KB
testcase_25 AC 151 ms
6,620 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

typedef struct {
	long long key;
	int id;
} data;

typedef struct {
	data obj[200001];
	int size;
} max_heap;

void push(max_heap* h, data x)
{
	int i = ++(h->size), j = i >> 1;
	data tmp;
	h->obj[i] = x;
	while (j > 0) {
		if (h->obj[i].key > h->obj[j].key) {
			tmp = h->obj[j];
			h->obj[j] = h->obj[i];
			h->obj[i] = tmp;
			i = j;
			j >>= 1;
		} else break;
	}
}

data pop(max_heap* h)
{
	int i = 1, j = 2;
	data output = h->obj[1], tmp;
	h->obj[1] = h->obj[(h->size)--];
	while (j <= h->size) {
		if (j < h->size && h->obj[j^1].key > h->obj[j].key) j ^= 1;
		if (h->obj[j].key > h->obj[i].key) {
			tmp = h->obj[j];
			h->obj[j] = h->obj[i];
			h->obj[i] = tmp;
			i = j;
			j <<= 1;
		} else break;
	}
	return output;
}

int main()
{
	int i, N, M, X, A, B;
	data d;
	max_heap h;
	h.size = 0;
	scanf("%d %d %d", &N, &M, &X);
	for (i = 1; i <= N; i++) {
		scanf("%d %d", &A, &B);
		d.key = A + X;
		d.id = B;
		push(&h, d);
	}
	
	int K, C, num[200001] = {};
	scanf("%d", &K);
	for (i = 1; i <= K; i++) {
		scanf("%d", &C);
		num[C]++;
	}
	
	int flag[200001] = {};
	long long ans = 0, tmp = 0;
	for (i = 1; i <= N; i++) {
		do {
			d = pop(&h);
			if (d.id > 0) {
				if (flag[d.id] == 0) {
					flag[d.id] = 1;
					tmp += d.key;
					break;
				} else {
					d.key -= X;
					d.id *= -1;
					push(&h, d);
				}
			} else {
				tmp += d.key;
				break;
			}
		} while (1);
		ans += tmp * num[i];
	}
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}
0