Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The current selected programming language is C . We emphasize the submission of a fully working code over partially correct but efficient code. Once submitted,
The current selected programming language is C We emphasize the submission of a fully working code over partially correct but efficient code. Once submitted, you cannot review this problem again. You can use printf to debug your code. The printf may not work in case of syntaxruntime error. The version of GCC being used is
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 citimes.
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 townsN
The next line consists of N spaceseparated integers countTown countTown countTownNrepresenting 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
num
countTowni num
Sigma countTowni
i num
Example
Input:
Output:
Explanation:
The first, second and third towns are chosen and times respectively.
The different towns are selected on successive days in a sequence: first, second, first, third, first, second, first, third, first, third, first.
So the maximum number of days during which a salesman can sell is HAVING THIS FUNCTION : int maxDaysToWorkarraysingleint countTown int answer; Write your code here return answer; COMPLETE THIS FUNCTION
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started