I’ve tried to solve this question in online round it passed all the sample test cases but failed all the hidden test cases,

M has N number of sticks in his box, the capacity of the box is K, so M decides to break his sticks in a ratio so that the sum of the squares of the length of the sticks is minimum.

Input format:

N-no.of inputs

K-capacity of sticks to be stored

N lines of input denoting the length of sticks

Sample

1

2

10

M has 1 stick of length 10 and he needs to fit 2 in his box, so he breaks the stick into 5 5 each so now 25+25=50

1

3

10

OP-34

This is my code which i’ve used:

n=int(input())

cap=int(input())

m1,m2=cap,cap

l=[]

for i in range(n):

x=int(input())

l.append(x)

l.sort()

n1,n2=l[n-1],l[n-1]

l.pop(n-1)

for i in range(m1-1):

t=int(n1/m2)

l.append(t)

n2-=t

l.append(n2)

sum1=0

for i in l:

sum1+=i**2

print(sum1)