-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrt.c
68 lines (67 loc) · 1.1 KB
/
brt.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <stdio.h>
#include <math.h>
#define MAX 100000
int findMin(int *arr, int n){
int min = arr[0];
for (int i = 0; i < n; i ++){
if (arr[i] < min)
min = arr[i];
}
return min;
}
void quickSort(int x[], int l , int r)
{
int temp;
if (l <= r)
{
int key = x[(l+r)/2];
int i = l;
int j = r;
while (i <= j)
{
while (x[i] < key)
i++;
while (x[j] > key)
j--;
if (i <= j)
{
temp=x[i];
x[i]=x[j];
x[j]=temp;
i++;
j--;
}
}
if (l < j)
quickSort(x, l, j);
if (r > i)
quickSort(x, i, r);
}
}
int main (){
int t;
scanf("%d", &t);
while (t --)
{
int n;
scanf("%d", &n);
int a[MAX];
int b[MAX];
for (int i = 0; i < n;i ++){
scanf("%d", &a[i]);
}
quickSort(a, 0, n - 1);
for (int i = 0; i < n - 1;i ++){
b[i] = abs(a[i + 1] - a[i]) ;
}
int count = 0;
int min = findMin(b, (n - 1));
printf("%d ", min);
for (int i = 0; i < n - 1;i ++){
if (b[i] == min)
count ++;
}
printf ("%d ", count);
printf("\n");
}
}