답안 #481396

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
481396 2021-10-20T16:25:10 Z rainboy Pod starim krovovima (COCI20_psk) C
40 / 50
1 ms 276 KB
#include <stdio.h>

#define N	1000

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

unsigned int X = 12345;

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

int aa[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 (aa[ii[j]] == aa[i_])
				j++;
			else if (aa[ii[j]] > aa[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 main() {
	static int ii[N];
	int n, i, k, sum;

	scanf("%d", &n);
	sum = 0;
	for (i = 0; i < n; i++) {
		int a;

		scanf("%d%d", &a, &aa[i]);
		sum += a;
		ii[i] = i;
	}
	sort(ii, 0, n);
	for (i = 0; i < n; i++) {
		int i_ = ii[i];

		aa[i_] = min(aa[i_], sum), sum -= aa[i_];
	}
	k = 0;
	for (i = 0; i < n; i++)
		if (aa[i] == 0)
			k++;
	printf("%d\n", k);
	for (i = 0; i < n; i++)
		printf("%d ", aa[i]);
	printf("\n");
	return 0;
}

Compilation message

psk.c: In function 'main':
psk.c:38:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
psk.c:43:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |   scanf("%d%d", &a, &aa[i]);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 276 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Incorrect 1 ms 204 KB Output isn't correct
10 Incorrect 1 ms 204 KB Output isn't correct