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 500000
#define INF 0x3f3f3f3f
unsigned int X = 12345;
int rand_() {
return (X *= 3) >> 1;
}
void sort(long long *dd, int l, int r) {
while (l < r) {
int i = l, j = l, k = r;
long long d = dd[l + rand_() % (r - l)], tmp;
while (j < k)
if (dd[j] == d)
j++;
else if (dd[j] < d) {
tmp = dd[i], dd[i] = dd[j], dd[j] = tmp;
i++, j++;
} else {
k--;
tmp = dd[j], dd[j] = dd[k], dd[k] = tmp;
}
sort(dd, l, i);
l = k;
}
}
int main() {
static long long dd[N];
int n, i;
long long m, l, l_, x;
scanf("%lld%lld%d", &m, &l, &n);
for (i = 0; i < n; i++)
scanf("%lld", &dd[i]);
sort(dd, 0, n);
x = 0;
for (i = n - 1; i >= 0 && x < l; i--) {
if (l - x > dd[i]) {
printf("0\n");
return 0;
}
x += dd[i] - (l - x);
}
if (x < l) {
printf("0\n");
return 0;
}
if (x >= m) {
printf("%d\n", n - 1 - i);
return 0;
}
if (i >= 0 && dd[i] >= m - l) {
printf("%d\n", n - i);
return 0;
}
i = 0;
while (i < n && dd[i] < m - l)
i++;
if (i == n) {
printf("0\n");
return 0;
}
l_ = l - (dd[i] - (m - l)) / 2;
n--;
while (i < n)
dd[i] = dd[i + 1], i++;
x = 0;
for (i = n - 1; i >= 0 && x < l_; i--) {
if (l - x > dd[i]) {
printf("0\n");
return 0;
}
x += dd[i] - (l - x);
}
printf("%d\n", x < l_ ? 0 : n - i);
return 0;
}
Compilation message (stderr)
tak.c: In function 'main':
tak.c:37:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
37 | scanf("%lld%lld%d", &m, &l, &n);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tak.c:39:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
39 | scanf("%lld", &dd[i]);
| ^~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |