Arrival time of the night bus
Statement
A company's night express bus runs through the night without a break. This bus leaves the terminal at A hours B minutes, and it takes C minutes to reach its destination. Traffic jams and rest stops along the way are ruled out, so the travel time is always taken as C minutes.
The clock at the terminal writes the day from 0 hours 0 minutes to 23 hours 59 minutes, and it does not write the date. So when the travel time is long enough that the arrival passes midnight, the arrival time falls on the next day. Even then the date is not written, only the hour and the minute. The travel time is at most 1,000 minutes, so midnight is never passed twice.
Write a program that prints the arrival time of the bus when the departure time and the travel time are given.
For example, suppose the bus leaves at 23 hours 59 minutes and takes 1,000 minutes. Rather than handling the hour and the minute apart, it is easier to turn the departure time into minutes and do the arithmetic there. A day is 1,440 minutes, so when the sum goes past 1,440 minutes you take 1,440 minutes off it. Writing the steps along the way as a table gives the following.
| Step | Value |
|---|---|
| Departure time turned into minutes | 1439 |
| After adding the travel time | 2439 |
| After taking off the 1,440 minutes of one day | 999 |
| Turned back into an hour and a minute | 16 hours 39 minutes |
So the arrival time in this case is 16 hours 39 minutes.
Putting other cases into one table gives the following.
| Departure time | 10 hours 10 minutes | 23 hours 59 minutes | 23 hours 59 minutes | 0 hours 0 minutes |
|---|---|---|---|---|
| Travel time | 50 minutes | 1 minute | 1,000 minutes | 0 minutes |
| Arrival time | 11 hours 0 minutes | 0 hours 0 minutes | 16 hours 39 minutes | 0 hours 0 minutes |
There are also cases where the travel time is 0 minutes. The arrival time is then the same as the departure time.
Input and output examples
Example 1
Input
10 10 50
Output
11 0
Example 2
Input
23 59 1000
Output
16 39
Example 3
Input
23 59 1
Output
0 0
Input
First the hour A and the minute B of the departure are given on the first line, in that order, separated by one space. A is an integer from 0 to 23, and B is an integer from 0 to 59. Next the travel time C to the destination is given on the second line as an integer in minutes. C is an integer from 0 to 1,000, and 0 can be given. C is never given in hours. The departure time and the travel time are given on separate lines, not together on one line.
Output
Print the hour and the minute of the arrival time on the first line, in that order, separated by one space. Write the hour and the minute as the numbers themselves, with no leading zero attached. For 0 hours 10 minutes you print 0 10. The space between the two numbers is a single space, and no space is attached after the minute.
Requirements
- The input is two lines, with the hour and the minute on the first line and the travel time on the second line
- A is an integer from 0 to 23, and B is an integer from 0 to 59
- C is an integer from 0 to 1,000, and it can be 0
- When the arrival passes midnight, write it as a time on the next day
- Do not attach a leading zero to the hour or to the minute
- You must write a program that reads from standard input and writes to standard output
- Trailing spaces at the end of a line and blank lines at the end of the output are ignored when grading
- The languages you can use are Python and JavaScript
- The memory limit is 256MB. The browser does not measure it, it only states it
- The time limit is set by measuring the setter's reference solution on the same runtime
- On this problem you submit code, not a prompt. That code runs in the browser on this device, and all that goes to the server is a fingerprint of the output and the time it took. Whether it is correct is decided by the server. The run time is a number each device reports, so the code and the device details are posted next to it on the leaderboard.
- The output has to match the expected value down to the character. A space inside a line counts the same as any other character.
- There are 15 cases, and 3 of them show the input together with the expected output. The rest are used only when you submit and are not shown on this page.
- You have to pass all 15 cases to solve this.
Examples
3 public cases. Judging also uses hidden cases. You have to pass all 15 cases to solve this.
10 10 50
11 0
23 59 1
0 0
23 59 1000
16 39
Solution
Your code runs on this device. Only the fingerprint of the output and the elapsed time go to the server. The server decides whether it is correct.
Submitting requires you to log in. Running against the public cases works without one.
You can test with 3 public cases. Submitting runs the hidden cases too.
People who solved this problem
Nobody yet. You could be the first.