Maximum Sum of Building Speed
Practice
3.6 (23 votes)
Algorithms
Easy
Hiring
Merge sort
Sorting
Problem
85% Success 8766 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You are the king of Pensville where you have \(2N\) workers.
All workers will be grouped in association of size 2,so a total of N associations have to be formed.
The building speed of the \(i^{th}\) worker is \(A_i\).
To make an association, you pick up 2 workers. Let the minimum building speed between both workers be x, then the association has the resultant building speed x.
You have to print the maximum value possible of the sum of building speeds of N associations if you make the associations optimally.

Constraints
\(1 \le N \le 5 * 10^4\)
\(1 \le A_i \le 10^4\)

Input
First line contains an integer N, representing the number of associations to be made.
Next line contains \(2N\) space separated integers, denoting the building speeds of \(2N\) workers.

Output
Print the maximum value possible of the sum of building speeds of all the associations.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
6 votes
Tags:
ApprovedData StructuresEasyImplementationMerge sortSimulationSortingapproved
Points:20
7 votes
Tags:
Merge SortSortingAlgorithmsGreedy Algorithms
Points:20
38 votes
Tags:
AlgorithmsApprovedEasyOpenSorting