Statistics

Problem Statement for "AliceGameEasy"

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 i 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:
AliceGameEasy
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 will be between 0 and 1,000,000,000,000(10^12), inclusive.

Examples

  1. 7

    14

    Returns: 2

    This final result is possible. One possibility is that Alice won turns 1, 2, and 4 (for 1+2+4 = 7 points) and Kirito won turns 3, 5, and 6 (for 3+5+6 = 14 points). However, there are also some other possibilities in which Alice only won two of the six turns, so the correct answer is 2.

  2. 10

    0

    Returns: 4

    There must have been four turns and Alice must have won all four of them.

  3. 932599670050

    67400241741

    Returns: 1047062

    Watch out for integer overflow.

  4. 7

    13

    Returns: -1

  5. 0

    0

    Returns: 0

  6. 100000

    400500

    Returns: 106

  7. 0

    999999911791

    Returns: 0

  8. 999999911791

    0

    Returns: 1414213

  9. 1

    999999911790

    Returns: 1

  10. 1414214

    999998497577

    Returns: 2

  11. 999999911790

    1

    Returns: 1414212

  12. 755026605409

    244973306382

    Returns: 714252

  13. 327847151564

    672152760227

    Returns: 254772

  14. 409837379097

    590162532694

    Returns: 327786

  15. 748528900969

    251471010822

    Returns: 705030

  16. 1000000000000

    1000000000000

    Returns: -1

  17. 1721808594

    809459382

    Returns: 30916

  18. 370348630933

    475032962138

    Returns: 325581

  19. 18445259637

    61023824148

    Returns: 49318

  20. 630095621324

    5590571252

    Returns: 1021811

  21. 4196528761

    7905339339

    Returns: 29835

  22. 69461238295

    17208884016

    Returns: 230822

  23. 78123582904

    139949412587

    Returns: 131359

  24. 201724440134

    93472940872

    Returns: 336000

  25. 48863154161

    593381923820

    Returns: 43967

  26. 46643712

    10104819

    Returns: 6158

  27. 499541006028

    133439692647

    Returns: 608546

  28. 10250297202

    15805696138

    Returns: 50485

  29. 440500239287

    476161145716

    Returns: 378133

  30. 55874012216

    418260930520

    Returns: 59176

  31. 318451193525

    155038345231

    Returns: 416284

  32. 1658763402

    9776719894

    Returns: 11398

  33. 18663724812

    3823859889

    Returns: 124623

  34. 679068884157

    228417834288

    Returns: 671314

  35. 88954282006

    2312940414

    Returns: 359227

  36. 214745562615

    17071268256

    Returns: 496130

  37. 1000000000000

    999999000000

    Returns: 585787

  38. 1

    1

    Returns: -1

  39. 1

    2

    Returns: 1

  40. 2

    2

    Returns: -1

  41. 3

    2

    Returns: -1

  42. 25

    30

    Returns: 3

  43. 0

    1

    Returns: 0

  44. 0

    4

    Returns: -1

  45. 1

    5

    Returns: 1

  46. 0

    7

    Returns: -1

  47. 0

    23

    Returns: -1

  48. 3

    18

    Returns: 1

  49. 6

    0

    Returns: 3

  50. 0

    2

    Returns: -1

  51. 250000250000

    250000250000

    Returns: 292894

  52. 13

    15

    Returns: 2

  53. 59735405820

    15

    Returns: 345640

  54. 500000499999

    1

    Returns: 999999

  55. 0

    15

    Returns: 0

  56. 1000000000

    1000000000

    Returns: -1

  57. 1

    20

    Returns: 1

  58. 0

    21

    Returns: 0

  59. 5000

    50

    Returns: 91

  60. 1

    0

    Returns: 1

  61. 0

    6

    Returns: 0

  62. 932599670051

    67400241741

    Returns: -1

  63. 2

    10

    Returns: -1

  64. 5000049999

    1

    Returns: 99999

  65. 5

    5

    Returns: 2


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)2024, TopCoder, Inc. All rights reserved.
This problem was used for: