Statistics

Problem Statement for "TheBoredomDivTwo"

Problem Statement

John and Brus are bored. They have n+m common friends. The first n of them are bored and other m are not. John chooses the j-th (1-based) friend for a talk. If the friend is not bored, he becomes bored after the talk. Brus does the same with the b-th (1-based) friend. Note that John and Brus can't choose the same friend.

You have to find the number of bored friends after the talks.

Definition

Class:
TheBoredomDivTwo
Method:
find
Parameters:
int, int, int, int
Returns:
int
Method signature:
int find(int n, int m, int j, int b)
(be sure your method is public)

Constraints

  • n will be between 1 and 47, inclusive.
  • m will be between 1 and 47, inclusive.
  • j will be between 1 and n+m, inclusive.
  • b will be between 1 and n+m, inclusive.
  • j and b will be different.

Examples

  1. 1

    1

    1

    2

    Returns: 2

    The first friend is already bored and the second friend becomes bored after the talk with Brus.

  2. 2

    1

    1

    2

    Returns: 2

    Here John and Brus choose two friends that are already bored.

  3. 1

    2

    3

    2

    Returns: 3

    All the friends become bored.

  4. 4

    7

    7

    4

    Returns: 5

  5. 9

    9

    18

    13

    Returns: 11

  6. 4

    7

    10

    6

    Returns: 6

  7. 5

    4

    7

    2

    Returns: 6

  8. 25

    42

    55

    52

    Returns: 27

  9. 40

    45

    28

    37

    Returns: 40

  10. 43

    37

    5

    47

    Returns: 44

  11. 23

    29

    51

    27

    Returns: 25

  12. 18

    36

    18

    31

    Returns: 19

  13. 18

    32

    23

    2

    Returns: 19

  14. 37

    21

    13

    6

    Returns: 37

  15. 8

    39

    16

    5

    Returns: 9

  16. 37

    2

    7

    3

    Returns: 37

  17. 20

    1

    10

    9

    Returns: 20

  18. 8

    29

    22

    23

    Returns: 10

  19. 6

    22

    8

    3

    Returns: 7

  20. 40

    8

    19

    38

    Returns: 40

  21. 32

    35

    32

    33

    Returns: 33

  22. 31

    46

    31

    32

    Returns: 32

  23. 38

    35

    38

    39

    Returns: 39

  24. 32

    35

    32

    33

    Returns: 33

  25. 41

    43

    41

    42

    Returns: 42

  26. 40

    37

    40

    41

    Returns: 41

  27. 31

    40

    31

    32

    Returns: 32

  28. 31

    41

    31

    32

    Returns: 32

  29. 32

    31

    32

    33

    Returns: 33

  30. 46

    39

    46

    47

    Returns: 47

  31. 1

    42

    41

    34

    Returns: 3

  32. 1

    45

    2

    40

    Returns: 3

  33. 1

    37

    29

    27

    Returns: 3

  34. 1

    29

    11

    13

    Returns: 3

  35. 1

    36

    15

    4

    Returns: 3

  36. 25

    1

    11

    23

    Returns: 25

  37. 40

    1

    5

    3

    Returns: 40

  38. 43

    1

    17

    15

    Returns: 43

  39. 23

    1

    11

    19

    Returns: 23

  40. 18

    1

    14

    3

    Returns: 18

  41. 1

    1

    1

    2

    Returns: 2

  42. 47

    47

    7

    19

    Returns: 47

  43. 47

    47

    64

    32

    Returns: 48

  44. 47

    47

    85

    13

    Returns: 48

  45. 47

    47

    69

    35

    Returns: 48

  46. 1

    47

    45

    37

    Returns: 3

  47. 47

    1

    45

    37

    Returns: 47

  48. 1

    2

    2

    3

    Returns: 3

  49. 40

    47

    40

    42

    Returns: 41

  50. 2

    2

    2

    1

    Returns: 2

  51. 1

    2

    1

    2

    Returns: 2

  52. 2

    3

    4

    5

    Returns: 4

  53. 5

    3

    6

    7

    Returns: 7

  54. 5

    5

    7

    8

    Returns: 7

  55. 1

    4

    2

    1

    Returns: 2

  56. 1

    4

    2

    3

    Returns: 3

  57. 4

    7

    11

    4

    Returns: 5

  58. 3

    1

    3

    1

    Returns: 3

  59. 10

    1

    1

    2

    Returns: 10

  60. 5

    10

    11

    12

    Returns: 7

  61. 10

    12

    5

    6

    Returns: 10

  62. 5

    10

    7

    8

    Returns: 7

  63. 5

    1

    2

    3

    Returns: 5

  64. 47

    47

    49

    56

    Returns: 49

  65. 47

    47

    48

    49

    Returns: 49

  66. 10

    10

    10

    1

    Returns: 10

  67. 3

    6

    4

    5

    Returns: 5


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: