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 100000
#define INF 0x3f3f3f3f
int min(int a, int b) { return a < b ? a : b; }
unsigned int X = 12345;
int rand_() {
return (X *= 3) >> 1;
}
void sort(int *xx, int l, int r) {
while (l < r) {
int i = l, j = l, k = r, x = xx[l + rand_() % (r - l)], tmp;
while (j < k)
if (xx[j] == x)
j++;
else if (xx[j] < x) {
tmp = xx[i], xx[i] = xx[j], xx[j] = tmp;
i++, j++;
} else {
k--;
tmp = xx[j], xx[j] = xx[k], xx[k] = tmp;
}
sort(xx, l, i);
l = k;
}
}
int main() {
static int xx[N];
int n, m, l, i, lower, upper, cnt;
scanf("%d%d%d", &n, &m, &l);
for (i = 0; i < n; i++)
scanf("%d", &xx[i]);
sort(xx, 0, n);
cnt = 0;
while (m--) {
int x, y;
scanf("%d%d", &x, &y);
lower = -1, upper = n;
while (upper - lower > 1) {
i = (lower + upper) / 2;
if (xx[i] <= x)
lower = i;
else
upper = i;
}
if (min(lower == -1 ? INF : x - xx[lower], upper == n ? INF : xx[upper] - x) + y <= l)
cnt++;
}
printf("%d\n", cnt);
return 0;
}
Compilation message (stderr)
hunter.c: In function 'main':
hunter.c:37:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
37 | scanf("%d%d%d", &n, &m, &l);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
hunter.c:39:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
39 | scanf("%d", &xx[i]);
| ^~~~~~~~~~~~~~~~~~~
hunter.c:45:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
45 | scanf("%d%d", &x, &y);
| ^~~~~~~~~~~~~~~~~~~~~
# | 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... |