TopcoderArchiveVisit Topcoder
SRM25 Aug 2014
SRM 639

AliceGame

Problem statement, definition, constraints, and public examples.

Problem Statement

Alice and Kirito just played a game. The game consisted of a finite (possibly empty) sequence of turns. You do not know the exact number of turns. The turns were numbered starting from 1. In each turn, exactly one of our two players won. The winner of turn i scored 2*i-1 points.

You are given two longs x and y. Find out whether it is possible that at the end of the game Alice had exactly x points and Kirito had exactly y points. If it is possible, return the smallest number of turns Alice could have won. If the given final result is not possible, return -1 instead.

Definition

Class:
AliceGame
Method:
findMinimumValue
Parameters:
long, long
Returns:
long
Method signature:
long findMinimumValue(long x, long y)
(be sure your method is public)

Constraints

  • x and y are between 0 and 1,000,000,000,000, inclusive.

Examples

  1. 8
    17
    Returns: 2
    This final result is possible. Alice must have won at least two turns. One possibility is that Alice won turns 2 and 3 (for 3+5 = 8 points) and Kirito won turns 1, 4, and 5 (for 1+7+9 = 17 points).
  2. 17
    8
    Returns: 3
  3. 0
    0
    Returns: 0
  4. 9
    9
    Returns: -1
  5. 500000
    500000
    Returns: 294
Back to all problems