AlgoUniversity
  • Go Back
Discussion
Max Projects :

Author

Akshay Sharma

Difficulty Level : Easy

Submissions : 697

Asked In : Wells-Fargo

Marks :100

: 6 | : 0

An employee in an organization has begun working on N projects (numbered 0 to N-1). Each week he/she can work on a single module of one of the projects. The modules that are chosen on any two successive weeks should come from different projects. A project i can have at most Ci modules.

The modules of the projects are such that a module is completed in a week.

Write an algorithm to determine the number of weeks the employee can work on projects following the above-mentioned rules.

Input

The first line of the input consists of an integer - num, representing the number of projects (N). ($$$1 \le num \le 5*10^4 $$$)

The next line consists of N space-separated integers - projC0, projC1, projCN-1, representing the number of modules of the projects.($$$1 \le projCi \le 10^7$$$)

Output

Print an integer representing the maximum number of weeks the employee can work on the projects

Example

Input
3 
7 2 3
Output
11

You need to login to view your submissions.

You need to login to view all submissions.

Loading...

Result : Executed

Loading...

Feel something is wrong with the test cases?

Result : Accepted

Test Cases :

You need to Log In
We're glad that you want to attempt this problem!

But to Run or Submit the Problem, you need to Log In.

Continue to Log In
Challenge Submitted!

Your challenge has been submitted successfully.

You will get a response soon via WhatsApp or Email.

Challenge
Facing issue while trying to solve the problem! Don't worry, we got you covered!

Do let us know your issue.

Looks good!
Please enter your issue / feedback.

How do we get in touch with you?
Looks good!
Please enter your phone no.
Looks good!
Please enter your email address.