#GL0000227. Tối đa tổng sức mạnh các thẻ đồ họa (Video Cards)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Tối đa tổng sức mạnh các thẻ đồ họa (Video Cards)
Video Cards
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
A shop sells video cards of powers . Buy any non-empty selection and choose one leading card with unchanged power . Every secondary card may have its power decreased to a positive integer no larger than its original power and divisible by . Maximize the total power of the chosen compatible cards; cards may be left unbought.
Input
First line contains ; second line has .
Output
Print the maximum total power.
Subtasks
-
Subtask 1 (20 points): .
-
Subtask 2 (30 points): .
-
Subtask 3 (50 points): .
Examples
Example 1
Input
4
3 2 15 9
Output
27
Explanation
Choose the card of power 3 as the leader and the cards of powers 15 and 9 as secondary cards. Their total is 27.
Example 2
Input
4
8 2 2 7
Output
18
Explanation
Choose a card of power 2 as the leader and reduce power 7 to power 6. The total is 8+2+2+6=18.