look for overflows. try this test case:
Your loop conditions are wrong, causing overflow.
The variable i in the
for loop should go upto min(k-1, n-k) instead of just k-1.
So, change this line
for(ll i = 0; i < k-1; i++)
for(ll i = 0; i < min(k-1, n-k); i++)
And your code will get Accepted (AC).
@c_utkarsh, bayya thank you!!I was breaking my head to figure out what was going wrong,thank you keep helping,many like me need your help.cheers!