Test Taking
Time limit1sMemory limit128 MB
Given N questions and a set of possible true-counts, choose a true/false answer key maximizing the worst-case number of correct answers.
- Level
Hard8 of 10
- Topics
- Math, Greedy, Implementation, Sorting
- Solved
- No attempts yet
Problem
Farmer John must take his annual farming-license test, which has () true/false questions. After a dismal result last year, his cow Bessie wants to help.
Bessie has inside information: the number of questions whose correct answer is 'true' is guaranteed to be one of (; ). She does not know the correct answer to any individual question — only the possible totals of 'true' answers.
Farmer John writes an answer ('true' or 'false') for every question. Because he knows nothing about any specific question, an adversary may choose both the actual number of 'true' answers (one of Bessie's values) and exactly which questions those are, so as to make Farmer John's score as low as possible. Farmer John wants to pick his answers so that the number of correct answers he is guaranteed — no matter what — is as large as possible.
For example, take with the count of 'true' answers being or . If Farmer John marks every question 'false', he gets all correct when the count is and correct when the count is , so at least are guaranteed. If instead he guesses that some answers are 'true', the adversary can make all of those wrong, dropping his guarantee to . Marking everything 'false' is therefore better, guaranteeing .
Given Bessie's information, determine the largest number of correct answers Farmer John can guarantee by playing optimally.
Input
- Line 1: two space-separated integers and .
- Lines : line contains a single integer .
(When there are no further lines.)
Output
- A single integer: the best score Farmer John is guaranteed to achieve.