SimpleGuess
SRM 499 · 2010-11-01 · by lyrically
SRM 499 · 2010-11-01 · by lyrically · Simple Math, Simple Search, Iteration
Problem Statement
Problem Statement
A cat and a rabbit are playing a simple number guessing game.
The cat chose two different positive integers X and Y.
He then told the rabbit several numbers.
One of those numbers was X + Y and another was X - Y.
The others were simply made up.
The rabbit thinks the cat prefers large numbers. Given aint[] hints containing the numbers the cat told the rabbit,
return the largest possible value of X * Y.
The rabbit thinks the cat prefers large numbers. Given a
Constraints
- hints will contain between 2 and 50 elements, inclusive.
- Each element of hints will be between 1 and 100, inclusive.
- All elements of hints will be distinct.
- There will exist at least one pair of positive integers (X, Y) such that both X + Y and X - Y are elements of hints.
Examples
0)
{ 1, 4, 5 }
Returns: 6
The rabbit can determine that (X, Y) = (3, 2).
1)
{ 1, 4, 5, 8 }
Returns: 12
Possible pairs (X, Y) are (3, 2) and (6, 2). The values of X * Y are 6 and 12, respectively, and the largest is 12.
2)
{ 9, 8, 7, 6, 5, 4, 3, 2, 1 }
Returns: 20
3)
{ 2, 100 }
Returns: 2499
4)
{ 50, 58, 47, 57, 40 }
Returns: 441
Submissions are judged against all 133 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Coding Area
Language: C++17 · define a public class SimpleGuess with a public method int getMaximum(vector<int> hints) · 133 test cases · 2 s / 256 MB per case