Problem Statement

Victor has bought a new album from his favorite group. The album contains N songs that are each songDuration seconds long. There's 5 seconds of silence between each pair of consecutive songs. At time 0, Victor starts listening to the album, and at that exact moment, his phone starts to ring. The phone rings every delay seconds, and each ring lasts 1 second (for example, for delay = 3, the phone will ring during the seconds 0, 3, 6 and so on). He cannot hear the rings while the music is playing because the volume is too loud. He can only hear rings during the silent intervals between songs. If a ring starts at the same moment that a song starts playing, he will not hear it. Similarly, if a ring stops at the same moment that a song stops playing, he will not hear it. The album will play exactly once, so after the last song ends, Victor will be able to hear the phone again. Return the time in seconds at which Victor will first hear the phone ring.

Definition

 Class: MissedCall Method: waitingTime Parameters: int, int, int Returns: int Method signature: int waitingTime(int N, int songDuration, int delay) (be sure your method is public)

Constraints

-N will between 1 and 20, inclusive.
-songDuration will between 1 and 180, inclusive.
-delay will between 1 and 20, inclusive.

Examples

0)

 `2` `5` `7`
`Returns: 7`
 Second 0: The first song starts playing, and the telephone rings. Second 1-4: The first song is playing. Second 5-6: Silence. Second 7: The telephone rings. Victor only misses the first ring.
1)

 `4` `5` `20`
`Returns: 40`
 Victor will not hear the phone until after the album ends.
2)

 `6` `9` `20`
`Returns: 40`
 Second 0: The first song starts playing, and the telephone rings. Second 1-8: The first song is playing. Second 9-13: Silence. Second 14-19: The second song is playing. Second 20: The second song is playing, and the telephone rings. Second 21-22: The second song is playing. Second 23-27: Silence. Second 28-36: The third song is playing. Second 37-39: Silence. Second 40: The telephone rings. Victor misses the first two rings.

Problem url:

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

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10068&pm=6783

VitalyGoldstein

Testers:

PabloGilberto , brett1479 , Olexiy

Simulation