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 E2025 · EasyTime arithmetic

Center the Lecture Break

National Olympiad — Municipal round (2025 season)

Submission name: interruption.cpp

Problem summary

A lecture has a known start and end time and needs an N-minute break. Make the lecture portions before and after the break as equal as possible in whole minutes; if they differ, the first portion must be longer. Find when the break begins.

Input

A, B, C, D, N on five lines: start hour and minute, end hour and minute, break duration.

Output

The break’s starting hour and minute.

Constraints

8 ≤ A ≤ C ≤ 19; 0 ≤ B,D ≤ 59; 1 ≤ N ≤ 360. The described break fits within the lecture.

Worked example

An independently prepared example for this explanation.

Input

10
15
11
25
20

Output

10 40

Solution analysis

  1. Convert each clock time to minutes since midnight: start=60A+B and end=60C+D. Subtract the break duration from end−start to find the actual lecture minutes.
  2. Split these minutes into two integer parts. The first must receive the extra minute when the total is odd, so its length is (actual+1)/2 using integer division.
  3. The sample spans 70 minutes, with 20 minutes of break, leaving 50 minutes of lecture. The first portion lasts 25 minutes, so the break begins at 10:15+25=10:40.

Why it works

Two nonnegative integer portions summing to actual differ least when they are its floor and ceiling halves. Choosing the ceiling first meets the tie direction, and adding that duration to the start gives the unique required break time.

Complexity: O(1) time and O(1) extra space.

Watch out. Subtract the break before halving. Do clock arithmetic in total minutes, then convert back with division and remainder by 60.

Commented C++17 solution

An independently written complete program with standard headers.

#include <iostream>
using namespace std;
int main() {
    int a, b, c, d, duration;
    cin >> a >> b >> c >> d >> duration;
    int start = 60 * a + b;
    int end = 60 * c + d;
    int lecture = end - start - duration;
    // Give the first lecture portion the extra minute when the total is odd.
    int breakStart = start + (lecture + 1) / 2;
    cout << breakStart / 60 << ' ' << breakStart % 60 << '\n';
}

Source: Arena Olimpiici ↗