#P6674. [CCO 2019] Card Scoring

[CCO 2019] Card Scoring

Description

You downloaded a card game.

The rules of this game are as follows:

  1. There are nn cards in total. Each card has a type. There are nn possible types, represented by integers 1n1 \sim n. There is also a scoring parameter kk.
  2. You draw these nn cards in order. For each card, you have two choices: take it or discard it.
  3. In all cases, you must ensure that the cards in your hand contain only one type.
  4. After finishing drawing cards, you may choose to score your hand. The score is calculated as follows: if you have xx cards, you gain x12kx^{\frac{1}{2}k} points. After scoring, your hand will be cleared, and the points will be added to your total score.

Now, you want to compute the maximum possible total score in this card game.

Input Format

The first line contains two integers k,nk, n.

The next nn lines each contain one integer, representing the type of a card.

Output Format

Output one real number in a single line, representing the maximum score that can be achieved.

3 5
1
2
2
1
1
6.656854249

4 5
1
2
2
1
1
9.0

Hint

Sample Explanation

Sample 1 Explanation

The best strategy is to discard no cards, and score after drawing the 1st, 3rd, and 5th cards. The score is 11.5+21.5+21.56.6568542491^{1.5} + 2^{1.5} + 2^{1.5} \approx 6.656854249.

Sample 2 Explanation

There are two optimal strategies. One is to discard the cards of type 22, and score after drawing the 5th card, gaining 32=93^2 = 9 points in total.

The other is the same as Sample 1, with score 12+22+22=91^{2} + 2^{2} + 2^{2} = 9.

SPJ Scoring Standard

Let your answer be pp and the standard answer be qq. If pqq106\frac{|p-q|}{q} \le 10^{-6}, you will be accepted.

Constraints and Limits

For 100%100\% of the testdata, it is guaranteed that 2k42 \le k \le 4, 1n1061 \le n \le 10^6, and the card type {1,n}\in \{1,n\}.

Subtask nn \le k=k = Points
1 2020 No special restrictions 1616
2 300300 22 44
3 No special restrictions 2020
4 5×1035 \times 10^3 1212
5 No special restrictions 44
6 No special restrictions 3636

Notes

This problem is translated from Canadian Computing Olympiad 2019 Day 2 T1 Card Scoring.

Translated by ChatGPT 5