# Can someone provide some testcases for this solution for CHEF & HILLS (CHILLS)?

n = int(input())
i = 0
ans = []

while i < n :
hh = input().split()
houses = int(hh)
hills = int(hh)
coo = [int(x) for x in input().split()]
if houses == 1 and hills == 1:
q = 0
ans.append(q)
elif houses == 1 and hills%2 == 0 :
q = hills//2
ans.append(q)
elif houses == 1 and hills%2 != 0 :
q = (hills - 1)//2
ans.append(q)
else :
ma = coo[-1] - coo + 1
if ma == hills :
w = 0
j = 0
while j < houses :
mo = coo[j] - coo
mt = coo[j] - coo[-1]
if mo < 0 :
mo = mo*(-1)
if mt < 0 :
mt = mt * (-1)
an = max(mo,mt)
w = w + an
j += 1
ans.append(w)
elif hills > ma :
nohill = hills - ma
dis = nohill//2
rf = coo[-1] + dis
lf = coo - (nohill - dis)
ww = 0
jj = 0
while jj < houses :
moo = coo[jj] - lf
mtt = coo[jj] - rf
if moo < 0 :
moo = moo*(-1)
if mtt < 0 :
mtt = mtt * (-1)
ann = max(moo,mtt)
ww = ww + ann
jj += 1
ans.append(ww)
elif hills < ma :
nohilll = ma - hills
diss = nohilll//2
rff = coo[-1] - diss
lff = coo + (nohilll - diss)
www = 0
jjj = 0
while jjj < houses :
mooo = coo[jjj] - lff
mttt = coo[jjj] - rff
if mooo < 0 :
mooo = mooo*(-1)
if mttt < 0 :
mttt = mttt * (-1)
annn = max(mooo,mttt)
www = www + annn
jjj += 1
ans.append(www)
else :
aq = 2/0
print(aq)
i += 1

for rr in ans :
print(rr)

Please either format your code or (better!) link to your submission - the forum software has mangled it and it won’t compile! 2 Likes

1 Like

CHILLS Problem - CodeChef Question link
CodeChef: Practical coding for everyone Submission link

1 Like

for input
1
3 1
1 3 3

AC O/P - 2