답안 #478885

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
478885 2021-10-08T19:03:07 Z rainboy Kisik (COCI19_kisik) C
90 / 90
722 ms 31856 KB
#include <stdio.h>

#define N	1000000
#define INF	0x3f3f3f3f3f3f3f3fLL

long long min(long long a, long long b) { return a < b ? a : b; }

unsigned int X = 12345;

int rand_() {
	return (X *= 3) >> 1;
}

int xx[N], yy[N], ii[N];

void sort(int *ii, int l, int r) {
	while (l < r) {
		int i = l, j = l, k = r, i_ = ii[l + rand_() % (r - l)], tmp;

		while (j < k)
			if (yy[ii[j]] == yy[i_])
				j++;
			else if (yy[ii[j]] < yy[i_]) {
				tmp = ii[i], ii[i] = ii[j], ii[j] = tmp;
				i++, j++;
			} else {
				k--;
				tmp = ii[j], ii[j] = ii[k], ii[k] = tmp;
			}
		sort(ii, l, i);
		l = k;
	}
}

int pq[N], iq[1 + N], cnt;

int lt(int i, int j) { return xx[i] > xx[j]; }

int p2(int p) {
	return (p *= 2) > cnt ? 0 : (p < cnt && lt(iq[p + 1], iq[p]) ? p + 1 : p);
}

void pq_up(int i) {
	int p, q, j;

	for (p = pq[i]; (q = p / 2) && lt(i, j = iq[q]); p = q)
		iq[pq[j] = p] = j;
	iq[pq[i] = p] = i;
}

void pq_dn(int i) {
	int p, q, j;

	for (p = pq[i]; (q = p2(p)) && lt(j = iq[q], i); p = q)
		iq[pq[j] = p] = j;
	iq[pq[i] = p] = i;
}

void pq_add(int i) {
	pq[i] = ++cnt, pq_up(i);
}

int pq_remove_first() {
	int i = iq[1], j = iq[cnt--];

	if (j != i)
		pq[j] = 1, pq_dn(j);
	pq[i] = 0;
	return i;
}

int main() {
	int n, k, i;
	long long x, ans;

	scanf("%d%d", &n, &k);
	for (i = 0; i < n; i++)
		scanf("%d%d", &xx[i], &yy[i]);
	for (i = 0; i < n; i++)
		ii[i] = i;
	sort(ii, 0, n);
	x = 0, ans = INF;
	for (i = 0; i < n; i++) {
		int i_ = ii[i];

		pq_add(i_), x += xx[i_];
		if (cnt > k)
			x -= xx[pq_remove_first()];
		if (cnt == k)
			ans = min(ans, x * yy[i_]);
	}
	printf("%lld\n", ans);
	return 0;
}

Compilation message

kisik.c: In function 'main':
kisik.c:76:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |  scanf("%d%d", &n, &k);
      |  ^~~~~~~~~~~~~~~~~~~~~
kisik.c:78:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |   scanf("%d%d", &xx[i], &yy[i]);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 163 ms 8864 KB Output is correct
2 Correct 462 ms 19656 KB Output is correct
3 Correct 284 ms 20128 KB Output is correct
4 Correct 251 ms 18492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 303 ms 13172 KB Output is correct
2 Correct 32 ms 2808 KB Output is correct
3 Correct 69 ms 5268 KB Output is correct
4 Correct 221 ms 16144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 122 ms 8140 KB Output is correct
2 Correct 349 ms 16100 KB Output is correct
3 Correct 258 ms 11608 KB Output is correct
4 Correct 473 ms 31856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 195 ms 9996 KB Output is correct
2 Correct 722 ms 28056 KB Output is correct
3 Correct 151 ms 8936 KB Output is correct
4 Correct 322 ms 22556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 485 ms 19912 KB Output is correct
2 Correct 371 ms 19772 KB Output is correct
3 Correct 306 ms 15440 KB Output is correct
4 Correct 139 ms 10768 KB Output is correct