GIRLSNBS - Girls and Boys
There are G girl students and B boy students in a class that is about to graduate. You need to arrange them in a single row for the graduation. To give a better impression of diversity, you want to avoid having too many girls or too many boys seating consecutively. You decided to arrange the students in order to minimize the gender regularity. The gender regularity of an arrangement is the maximum number of students of the same gender (all girls or all boys) that appear consecutively. Given G and B, calculate the minimum gender regularity among all possible arrangements.
Input
Each test case is described using a single line. The line contains two integers G and B representing the number of girls and boys in the class, respectively (0 ≤ G, B ≤ 1000). The end of input is indicated with a line containing the number −1 twice.
Output
For each test case, output a single line with a single integer representing the minimum gender regularity that an arrangement of G girls and B boys can have.
Example
Input:
10 10
5 1
0 1000
-1 -1
Output:
1
3
1000
hide comments
akihisa:
2021-12-28 14:58:43
0 0
|
|
Waseem Ahmed:
2021-06-27 10:34:25
Simple pigeon hole. Not expected as a SPOJ level problem. |
|
deerawat:
2020-12-24 18:17:12
YES take care of 0 0 |
|
harsh_ag7654:
2020-09-12 17:54:19
take care of 0 0 took me 10 mins to figure out
|
|
zimpzamp:
2020-09-01 18:26:20
I was not able to do this by using Pigeon Hole Principle (intentionally) but I rather simulated the whole process because constraints are small. |
|
ckanzz:
2020-08-27 21:26:47
Try using pigeon hole concept, learned something new and really cool, take your time and understand the concept |
|
gauravgupta14:
2020-08-02 05:24:16
hi |
|
amar_shukla1:
2020-06-24 17:23:24
Actually implemented it as I was seeing a pattern.
|
|
pavan_putra:
2020-06-10 13:26:20
pigeon hole :))))) |
|
coolboy7:
2020-06-05 08:59:00
This is one of the easiest questions;) |
Added by: | Pablo Ariel Heiber |
Date: | 2010-09-27 |
Time limit: | 2s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 NODEJS OBJC VB.NET |
Resource: | FCEyN UBA ICPC Selection 2010 |