Grab A Seat
All submissions for this problem are available.
It's interesting to see where people sit when entering a room of other people that they do not know. One of the strategies is that when a person enters a room, they will sit at a location that maximizes the distance between themselves and the closest other person. If multiple seats are equally far, then the person will sit closer to the entrance of the room. The seats are numbered from 1 to N, where 1 is the closest to the entrance and N is the furthest.
The only in the input consists of N and P. N is the number of seats in the room, P is the number of people entering this room. 1 <= N <= 1000 and 1 <= P <= N.
The output contains the seat number in which the Pth person is seating.
Input: 5 4 Output: 2
|Time Limit:||0.145455 - 0.32 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.5, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, CLOJ, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.