We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
defSolve(n,s,k,l=0):m=s%nifk<(m*(n-m)):returnFalseif(n-1)*s<k:returnFalseh=n+(s<<6)+(k<<14)+(l<<25)ifn==1:ifk:returnFalsedp[h]=sifhindp:ifdp[h]==-1:returnFalsereturnTrueforiinrange(l,s// n + 1):p=k-((s-i)-i*(n-1))ifp<0:continueifSolve(n-1,s-i,p,i):dp[h]=ireturnTruedp[h]=-1returnFalsedp={}foriinrange(int(input())):n,s,k=map(int,input().split())ifSolve(n,s,k):i=0h=n+(s<<6)+(k<<14)+(i<<25)whilehindp:i=dp[h]k-=((s-i)-i*(n-1))n-=1s-=ih=n+(s<<6)+(k<<14)+(i<<25)print(i,end=" ")print("")else:print(-1)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Array Construction
You are viewing a single comment's thread. Return to all comments →
PyPy 3 solution