# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
481397 | rainboy | Pod starim krovovima (COCI20_psk) | C11 | 1 ms | 204 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |