You are viewing a single comment's thread. Return to all comments →
int equal(vector<int>&arr){ sort(arr.begin(),arr.end()); int n = arr.size(); int ops0 = 0,ops1 = 0,ops2 = 0,num,mini = arr[0]; for(int i = 1;i<n;i++){ num = arr[i] - mini; ops0 += num/5 + (num%5)/2 + (num%5)%2; ops1 += (num+1)/5 + ((num+1)%5)/2 + ((num+1)%5)%2; ops2 += (num+2)/5 + ((num+2)%5)/2 + ((num+2)%5)%2; } return min(ops0,min(ops1+1,ops2+1)); }
Seems like cookies are disabled on this browser, please enable them to open this website
Equal
You are viewing a single comment's thread. Return to all comments →
C++ code by Shikhar Mishra