-
Notifications
You must be signed in to change notification settings - Fork 62
/
EQUAL
74 lines (68 loc) · 1.32 KB
/
EQUAL
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
69
70
71
72
73
74
#include<iostream>
#include<cstdio>
#define INT_MAX 2000000000
using namespace std;
long long int functn (long long int temp) // similar to greedy Coin-change
{
long long int x=0;
if(temp>=5)
{
x = temp/5;
temp = temp%5;
}
if(temp>=2)
{
x += temp/2;
temp = temp%2;
}
x += temp;
return x;
}
int array_smallest(long long int array[],int array_length)
{
long long int smallest = INT_MAX;
long long int i;
for (i = 0; i < array_length; i++)
{
if (array[i] < smallest) {
smallest = array[i];
}
}
return smallest;
}
long long int mod(long long int x)
{
if(x>0)
return x;
else
return (-1)*x;
}
int main()
{
long long int T,N,i,j,min,sum,temp;
cin>>T;
while(T--)
{
min = 1000000;
cin>>N;
int A[N];
for(i=0 ; i< N ; i++)
{
cin>>A[i];
if(A[i]<min)
min = A[i];
}
long long int sum[6];
for(j=0 ; j<=5 ; j++)
{
sum[j]=0;
for(i=0 ; i< N ; i++)
{
temp = mod(A[i] - (min-j));
sum[j] = sum[j] + functn(temp);
}
}
cout<<array_smallest(sum,6)<<endl;
}
return 0;
}