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
- 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.
- 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.
- 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.
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';
}