답안 #481397

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

#define N	1000

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 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;
	long long 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:39:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
psk.c:44:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |   scanf("%d%d", &a, &aa[i]);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 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 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct