/* Topcoder SRM 499, D2, 250-Pointer (SimpleGuess) James S. Plank Mon Aug 29 19:46:03 EDT 2016 */ #include #include #include #include #include #include using namespace std; class SimpleGuess { public: int getMaximum(vector hints); }; int SimpleGuess::getMaximum(vector hints) { set S; int ans; int X, Y; int i; /* First, create a set S with all of the hints. That way, you can enumerate X and Y, and look up X-Y and X+Y in the set */ for (i = 0; i < hints.size(); i++) S.insert(hints[i]); /* Sentinelize -- Start ans at -1, so any legal answer will be greater than it */ ans = -1; /* Now, enumerate all X/Y pairs, and look for X+Y and X-Y in the set. If they are both there, and if X*Y is bigger than the current best answer, set the answer. */ for (X = 1; X <= 100; X++) { for (Y = 1; Y < X; Y++) { if (S.find(X-Y) != S.end() && S.find(X+Y) != S.end() && X*Y > ans) { ans = X*Y; } } } return ans; }