#include <stdio.h>
#include <limits.h>
#include <stdlib.h>
int compar(const void *i, const void *j)
{
return *(int*)i - *(int*)j;
}
void *ptr;
int compar_(const void *i, const void *j)
{
int *a;
a = ptr;
return a[*(int*)i] - a[*(int*)j];
}
void chmin(int *a, int b)
{
if (b < *a)
{
*a = b;
}
}
int main()
{
int n, t, i, min, range;
static int a[1 << 19], b[1 << 19], c[1 << 19];
range = INT_MAX;
scanf("%d%d", &n, &t);
for (i = 0; i < n; ++i)
{
scanf("%d", a + i);
c[i] = a[i] % t;
b[i] = i;
}
ptr = c;
qsort(a, n, sizeof *a, compar);
min = a[0];
qsort(b, n, sizeof *b, compar_);
for (i = 0; i < n; ++i)
{
if (c[b[i]] <= min)
{
if (i)
{
chmin(&range, t + c[b[i - 1]] - c[b[i]]);
}
else
{
chmin(&range, c[b[n - 1]] - c[b[0]]);
}
}
}
printf("%d\n", (range + 1) / 2);
return 0;
}
Compilation message (stderr)
Main.c: In function 'main':
Main.c:34:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
34 | scanf("%d%d", &n, &t);
| ^~~~~~~~~~~~~~~~~~~~~
Main.c:37:5: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
37 | scanf("%d", a + 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... |