## WC '18 Contest 3 J2 - Net Weight

View as PDF

Points: 5 (partial)
Time limit: 1.0s
Memory limit: 16M

Author:
Problem type
##### Woburn Challenge 2018-19 Round 3 - Junior Division

Oh boy, is it ever Team Rocket's lucky day: They've stumbled upon a gathering of wild, defenseless Pikachus! This is their chance to snatch up as many of these priceless Pokémon as they can!

Jessie and James each have a net, which can allow them to catch at most one Pikachu each. There's just one possible caveat: Each net can only hold a Pikachu which weighs at most pounds. The -th of the Pikachus has a weight of pounds.

Heavier Pikachus are sure to be more valuable, so Team Rocket would like to catch the heaviest ones they can. Given that Jessie and James each choose at most one Pikachu to catch (and don't both catch the same Pikachu), such that each of their chosen Pikachus weighs at most pounds, what's the maximum possible sum of Pikachu weights which they can get their hands on?

#### Input Specification

The first line of input consists of a single integer, .
lines follow, the -th of which consists of a single integer, , for .

#### Output Specification

Output a single integer, the maximum combined weight of Pikachus which Team Rocket can catch (in pounds).

#### Sample Input 1

5
43
100
31
104
62

#### Sample Output 1

162

#### Sample Input 2

3
101
1
200

#### Sample Output 2

1

#### Sample Explanation

In the first case, Jessie can catch the -nd Pikachu while James catches the -th Pikachu, for a combined weight of pounds.

In the second case, Jessie can catch the -nd Pikachu while James catches none.