No Thanks!
InterviewTime limit1sMemory limit512 MB
Given a set of distinct card numbers, score the pile as the sum of each card that does not have a consecutive predecessor among the collected cards.
- Level
Easy3 of 10
- Topics
- Hash map, Array, Implementation
- Solved
- No attempts yet
Problem
In the card game “No Thanks,” the deck consists of cards numbered through , and players collect cards into their score pile as the game is played. A player’s final score is the sum of the numbers on the collected cards, with one exception: if a player has collected any cards with two or more consecutive numbers, only the smallest number in that group counts toward the score. Your job is to compute the score for a single player’s pile of cards, though here the deck may be much larger than cards.
Input
The first line contains one integer, , the number of cards collected. The second line contains integers, the numbers on the collected cards. You may assume that , all card values are in the range inclusive, and no card value is repeated.
Output
Output a single line containing the score for the given set of cards.