PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#QHD0000012. Chán nản (Boredom)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Chán nản (Boredom)
Boredom
Source: Codeforces
Problem Statement
You are given a sequence of positive integers . You may perform the following move repeatedly, stopping whenever you choose or when the sequence becomes empty:
Choose one element with value , earn points and delete that chosen element. At the same time, delete every remaining element whose value equals or . Other elements equal to remain and may be selected later.
Find the maximum total score achievable.
Input
The first line contains , the number of initial elements.
The second line contains integers .
Output
Print one integer: the maximum total score.
Subtasks
- Subtask 1 (20 points): ; ().
- Subtask 2 (30 points): ; ().
- Subtask 3 (50 points): ; ().
Examples
Input
2
1 2
Output
2
Explanation
Taking removes and earns only point. Taking removes and earns points, so the optimal total is .