cppAcademy
FROM LEARNING TO COMPETING

Beginner.
Your first challenges.

Bulgarian Informatics Group E · 2007–2026

270 independently explained problems: 54 Municipal, 54 Regional, 105 National Olympiad tasks and 57 Autumn Tournament tasks. Start with the easier tasks and work upwards. Difficulty labels are learning estimates, not official ratings; Group E also includes challenging national-level problems. Years follow Arena’s competition-season labels. Source clarifications are noted on affected tasks.
GROUP E2024 · EasyTime arithmetic

Television Sleep Timer

Autumn Tournament (2024)

Submission name: cat.cpp

Problem summary

A television timer is set at hour h and minute m to switch the television off N minutes later. Find the switch-off time on a 24-hour clock.

Input

h and m on the first line; N on the second.

Output

The switch-off time in hh:mm format.

Constraints

0 ≤ h ≤ 23; 0 ≤ m ≤ 59; 0 ≤ N ≤ 100000.

Worked example

The example is reproduced from the original tournament statement.

Input

23 10
70

Output

00:20

Solution analysis

  1. Convert h:m into 60h+m minutes after midnight. Adding N now handles all minute-to-hour carries automatically.
  2. Only the time of day is required. Reduce the sum modulo 1440, then divide by 60 for hours and take the remainder for minutes.
  3. At 23:10 there are 1390 elapsed minutes. Adding 70 gives 1460; modulo 1440 leaves 20, which is 00:20.

Why it works

Minute conversion preserves elapsed time. Every complete 1440-minute day leaves the same clock display, so the remainder identifies the switch-off time. Quotient and remainder by 60 recover its hour and minute.

Complexity: O(1) time and O(1) extra space; all loops have a fixed upper bound.

Watch out. N can span many days. Print leading zeros, including at midnight.

Commented C++17 solution

An independently written complete program with standard headers.

// Key idea: Minute conversion preserves elapsed time. Every complete 1440-minute day leaves the same
// clock display, so the remainder identifies the switch-off time.
#include<iostream>
#include<iomanip>
using namespace std;
int main(){
    int h,m,n;
    cin>>h>>m>>n;
    int time=(h*60+m+n)%1440;
    cout<<setfill('0')<<setw(2)<<time/60<<':';
    cout<<setw(2)<<time%60<<'\n';
}

Source: Arena Olimpiici ↗