Your code will fail for below test case
6 2 30 42
In your code, for this test case, pref[n-1] would be 2 and your code will print the answer as 20.
But optimally, we can change the salary of employee at index 1 from 2 to 6 (New Salaries [6,6,30,42]) and then we will pay all the salaries with denomination value as 6 and the minimum number of notes required will be 14
My code is giving TLE, what am I doing wrong Solution: 48641143 | CodeChef