# QUCOBIC - Editorial

Contest

Practice

Author: grebnesieh

Tester: krooonal

Easy

### PREREQUISITES

Working of a 24 hour clock.

### PROBLEM

Given the current time of a 24 hour clock in the format hhmm, return the maximal time it could display in s seconds.

### EXPLANATION

This was supposed to be the easiest problem here. I actually did get the idea for this one while in class getting bored but I am not sure if a codechef long contest was involved or not. xD

Pretty straightforward problem, with plenty of edge cases, one of which is:

INPUT

``````1
2359
10
``````

OUTPUT

``````2359
``````

If it makes you feel any better, I failed at it too. (yay, problem testing)

The idea here is that while the 24 hour clock displays the hours and minutes, it hides the seconds, which could be anywhere between 00 and 59.

This difference of 60 seconds can produce 2 seperate times if you consider the time displayed by the clock S seconds later. For example, for the given test case:

``````1
1234
123
``````

the clock could be 12:34:59 initially and hence 123 seconds later it will have, 12:37:22, leading to a display of 1237.

We can simply measure time at both ends, adjust for day changes and arrive at an answer.

``````ans in seconds = max((hh * 3600 + mm * 60 + s) % 86400, (hh * 3600 + mm * 60 + s + 59) % 86400)
``````

Now, it is simply a matter of converting back to hours and minutes.

Which gives us a complete code (Python) of:

``````for _ in xrange(input()):
hhmm = int(raw_input())
hh, mm = hhmm / 100, hhmm % 100
s = input()
s = max((hh * 3600 + mm * 60 + s) % 86400, (hh * 3600 + mm * 60 + s + 59) % 86400)
hh, mm = s / 3600, (s % 3600) / 60
print str(hh).zfill(2) + str(mm).zfill(2)
``````
1 Like

yeah that 2359 or 0000 was tricky costed me 3 WA hey can you explain what will be output of
1
2358
120

It has to be 0000 because:
23:58:00 + 120s => 00:00:00 => you see 00:00
AND
23:58:59 + 120s => 00:00:59 => you see 00:00.

still not getting why 2359 and 10 outputs 2359.

How can I practice this problem?

1 Like

Where is this problem for practice??

If the clock starts with 23:59:00, after 10 seconds it is 23:59:10.

If the clock starts with 23:59:59, after 10 seconds it is 00:00:09.

Out of all other initial possible times you will only get either 2359 or 0000. And 2359 > 0000. So the answer is 2359.

1234, 123 ==> 1237

But I admin didn’t approve the request.

My comment was:
How can 1234 will become 1237 in 123 seconds.
Till 59 seconds, clock will show 1234. At 60th second it will show 1235. Similarly on 120th second it will start showing 1236. And till 179th sec it will show 1236 only.

Admin had weird thing in mind. The assumption in his mind is 12:34:59 as initial time.

Admin MUST not do such things.

@mon95 but than maximum time will be 2359 not 0000. I am confused with this only

thankyou grebnesieh!

when can we submit the practice problem for the same?