#P2988. [USACO10MAR] Test Taking S

[USACO10MAR] Test Taking S

Description

Farmer John has to take his annual farming license test. The test has NN (1N1,000,0001 \le N \le 1{,}000{,}000) true/false questions. After last year's poor performance, Bessie wants to help him.

Bessie knows that the number of questions whose answer is 'true' is one of t1,t2,,tKt_1, t_2, \dots, t_K (0tiN0 \le t_i \le N; 0K10,0000 \le K \le 10{,}000). She has no information about which particular questions are true. Using only this information, she wants to know the best score Farmer John can always guarantee, even without knowing any individual answers.

Example: For N=6N = 6 and possible counts {0,3}\{0, 3\}, if FJ answers 'false' on every question, then if the true count is 00 he gets 66 correct, and if it is 33 he gets 33 correct. So he can guarantee at least 33 correct.

By contrast, if FJ answers 'true' on exactly 33 questions and 'false' on the other 33, then if the true count is 00 he gets 33 correct, but if the true count is 33 he could get as few as 00 correct (if he guessed 'true' on the 33 that are actually 'false'). So this strategy does not guarantee any correct answers.

Given Bessie's information, compute the maximum number of answers FJ can always get correct if he uses an optimal strategy.

Constraints: 1N1,000,0001 \le N \le 1{,}000{,}000, 0K10,0000 \le K \le 10{,}000, 0tiN0 \le t_i \le N.

Input Format

  • Line 1: Two space-separated integers NN and KK.
  • Lines 2..K+12..K+1: Line i+1i+1 contains a single integer tit_i.

Output Format

  • Line 1: A single integer, the best score FJ is guaranteed to achieve.
6 2 
0 
3 

3 

Hint

Translation provided by @fan404.

Translated by ChatGPT 5