Company: Tech Mahindra_6oct
Difficulty: medium
Maximum Sales Days Problem Description A travelling salesperson works in N towns. Each day the salesperson sells products in one of the towns. The towns that are chosen on any two successive days should be different, and a town i can be chosen at most c_i times. Write an algorithm to determine the number of days when the salesperson can sell in the given towns following these rules. Input The first line of the input consists of an integer - num , representing the number of towns (N). The next line consists of N space-separated integers - countTown_0, countTown_1, ..., countTown_N-1 , representing the number of times each town can be chosen. Output Print an integer representing the maximum number of days during which the salesman can work. Constraints 1 ≤ num ≤ 5 * 10^4 1 ≤ countTown_i ≤ num ∑ countTown_i ≤ 10^5 0 ≤ i < num Examples Example 1: Input: 3 7 2 3 Output: 11 Explanation: The first, second and third towns are chosen 7, 2 and 3 times respectively. The d