#K71047. Maximizing Book Discount
Maximizing Book Discount
Maximizing Book Discount
You are given a set of books with their respective prices. A special discount is applied when a customer chooses a subset of books such that the total price of the selected books is a prime number. In such a case, the discount is equal to the smallest price among the chosen books. Your task is to determine the maximum discount a customer can get by choosing an appropriate subset.
For a subset with prices \(p_1, p_2, \dots, p_k\), let \(S = p_1 + p_2 + \dots + p_k\). If \(S\) is prime, then the discount offered by that subset is \(\min\{p_1,p_2,\dots,p_k\}\). You need to consider all non-empty subsets and output the maximum discount among those subsets. If no subset yields a prime sum, output 0.
inputFormat
The input is read from stdin and consists of two lines:
- The first line contains an integer \(n\) representing the number of books.
- The second line contains \(n\) space-separated integers \(p_1, p_2, \dots, p_n\) indicating the prices of the books.
outputFormat
Output a single integer to stdout representing the maximum discount obtainable. If no valid subset exists (i.e. no subset sums to a prime number), output 0.
## sample5
6 10 3 15 7
7
</p>