Problem: Array Game — https://mirror.codeforces.com/contest/1904/problem/C Idea of the code, consider all possible combinations of 2 elements to make diff, mn = min of, mn, diff, [first element greater than diff]-diff, [one element left of the first element greater than diff]-diff. Thanks so much.
My Code
my man
k==2
case will get you to a nicen^2
TLE you must use binary search for each differenceThe time complexity of n^2logn was correct if you look at the editorial
Oops wow. I solved it in nlog(n) and never checked the constraints wow
I dont even think thats possible
Yes you can sort the array and check for each
$$$x=a_{i+1}-a_{i}$$$
what is the closest element to it from the right and left
and consider them in the answer
You answer is the minimum amoung these
at k==2 for(int i=0; i<n-1;i++) You put i<n-2, so you skipped one check
Try a=[5,98,99], ans is 1, but you get 4 because 98-(99-5)=4
im dumb asf thanks man