some test cases r not running
Https://ide.codingblocks.com/s/253527
You cannot sort the array initially. That condition will give you WA.
For example:
2
4
20 30 40 10
For this the correct answer is 50. But your code will give 60. Your code processes the array 10 20 30 40 but the actual array is 20 30 40 10.
This is because it is given in the question: Every painter can paint only contiguous segments of boards.
If you sort the array this condition is violated.