You are viewing a single comment's thread. Return to all comments →
This is exactly my way, but python is too slow and I get timeout in one of the test cases. anyone have any suggestion about optimizing this code:
n=int(input()) k=int(input()) ls=sorted([int(input()) for i in range(n)]) mnt=ls[-1]-ls[0] for i in range(n-k+1): seg=ls[i:i+k] d=seg[-1]-seg[0] if d<mnt: mnt=d print(mnt)
Seems like cookies are disabled on this browser, please enable them to open this website
Max Min
You are viewing a single comment's thread. Return to all comments →
This is exactly my way, but python is too slow and I get timeout in one of the test cases. anyone have any suggestion about optimizing this code: