All Tracks Data Structures Stacks Basics of Stacks Problem

Frustrated coders
Tag(s):

Easy, Sorting

Problem
Editorial
Analytics

AND THAT TOO IN C !!!

CAN IT GET ANY WORSE :P


There are frustrated coders standing in a circle with a gun in their hands. Each coder has a skill value S[ i ] and he can only kill those coders that have strictly less skill than him. One more thing, all the guns have only 1 bullet. This roulette can take place in any random order. Fortunately, you have the time stone (haaan wo harre wala) and you can see all possible outcomes of this scenario. Find the outcome where the total sum of the remaining coder's skill is minimum. Print this sum.


INPUT

The first line contains the no. of coders

The next line contains  elements where the ith element is theS[ i ] of ith coder.


OUTPUT

Print a single line containing the minimum sum


CONSTRAINTS

1<= N <= 1000000

1<=S[ i ]<=1000

SAMPLE INPUT
6
1 7 2 2 4 4
SAMPLE OUTPUT
11
Explanation

the coder of skill 2 kills coder skill 1

Both coders of skill 4 kill both coders of skill 2

the coder of skill 7 kills 1 coder of skill 4

remaining skills = 7+4 = 11

Time Limit: 1.0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: Bash, C, C++, C++14, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Julia, Kotlin, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Swift, Swift-4.1, TypeScript, Visual Basic

CODE EDITOR

Initializing Code Editor...
Your Rating:

Contributor

Notifications
View All Notifications

?