PROBLEM STATEMENT
Professor Smith teaches a logic class. One day, he writes some statements on the blackboard:
Exactly a of these statements are true.
Exactly b of these statements are true.
Exactly c of these statements are true.
.
.
.
Each of a, b, c and so on is a number. He then asks the class how many of the statements are true.
You will be given a vector statements, containing the numbers written in Professor Smith's
statements. Return the number of the statements that are true. If there is more than one possible
answer, return the largest one. If there are no possible answers, return -1.
DEFINITION
Class:TrueStatements
Method:numberTrue
Parameters:vector
Returns:int
Method signature:int numberTrue(vector statements)
CONSTRAINTS
-statements will contain between 1 and 50 elements, inclusive.
-Each element of statements will be between 0 and 50, inclusive.
EXAMPLES
0)
{0, 1, 2, 3}
Returns: 1
The 2nd statement is true (there is one true statement) and the others are false.
1)
{0}
Returns: -1
This is the Epimedes paradox: if the statement is true then it claims to be false, but if it is
false then it must be true.
2)
{0, 3, 1, 3, 2, 3}
Returns: 3
One solution is that the 3rd statement is the only true statement. However, it is also possible
that the 2nd, 4th and 6th statements are true (all of which say that 3 statements are true), and
the largest solution must be returned.
3)
{1, 1}
Returns: 0
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.