TopCoder problem "TheBoredomDivTwo" used in SRM 488 (Division II Level One)



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

0)
    
1
1
1
2
Returns: 2
The first friend is already bored and the second friend becomes bored after the talk with Brus.
1)
    
2
1
1
2
Returns: 2
Here John and Brus choose two friends that are already bored.
2)
    
1
2
3
2
Returns: 3
All the friends become bored.
3)
    
4
7
7
4
Returns: 5

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=11194

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=14241&pm=11194

Writer:

Vasyl[alphacom]

Testers:

PabloGilberto , ivan_metelsky , nika

Problem categories:

Advanced Math, Encryption/Compression