Every minute can pass only k cars, which means after if there were M cars at the Ith minute, then if that number is less or equal than k than all will pass or else the remaining M-k cars will be left to pass on the I+1 th minute. We need to do this on our given array, loop over it from 1 to n and see if the current element is less or equal than k then turn it to 0 and move on, otherwise subtract k and add the remaining number to A[I+1] . The final answer will be held in the element A[n+1]
No comments:
Post a Comment