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[0])
hills = int(hh[1])
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[0] + 1
if ma == hills :
w = 0
j = 0
while j < houses :
mo = coo[j] - coo[0]
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[0] - (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[0] + (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! :slight_smile:

2 Likes

I’ll appreciate if you will attach the link of your question as well as your submission.

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
Your O/P - 3

1 Like

Thanks for the help.
But all the houses have to be in a distinct position, so (1 3 3) is not possible.

1 Like