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

Departure Time

Autumn Tournament (2018)

Submission name: traveltime.cpp

Problem summary

A group of br pupils and one leader must travel, check into a hotel, register, and reach a conference at least 10 minutes before it starts. Given the conference time, registration duration, journey duration and hotel check-in duration per person, find the latest same-day departure.

Source clarification. The input description calls t6 the time for one pupil, but both official samples require applying it to br + 1 people, including the leader. The statement requires travel within the same day and defines no impossible-case output.

Input

Line 1: conference hour t1 and minute t2. Line 2: registration minutes t3. Line 3: journey hours t4 and minutes t5. Line 4: pupil count br. Line 5: hotel minutes per person t6.

Output

Departure hour and minute, separated by a space and each printed with two digits.

Constraints

0 ≤ t1, t4 ≤ 23; 0 ≤ t2, t3, t5, t6 ≤ 59; 1 ≤ br ≤ 100. The journey and conference are within the same day.

Worked example

First official statement sample.

Input

17 10
15
7 37
6
15

Output

07 23

Solution analysis

  1. Convert both clock times and durations into minutes. Hotel check-in takes (br + 1) × t6 minutes because the leader also checks in.
  2. Subtract journey time, hotel time, registration time and the required 10-minute margin from the conference start. Divide the resulting minute count by 60 for the hour and take its remainder for the minute.
  3. In the first sample, the conference starts at minute 1030. Subtract 457 journey minutes, 105 hotel minutes, 15 registration minutes and 10 early-arrival minutes. This leaves 443 minutes, or 07 23.

Why it works

The required activities consume exactly the sum of their durations before the 10-minute deadline. Subtracting this sum from the conference time gives a feasible departure at the deadline. Any later departure shifts arrival later and violates it, so the result is latest.

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

Watch out. Include the leader in the hotel count and print leading zeros. The source provides no output convention for an impossible same-day itinerary; the algorithm uses its stated same-day requirement.

Commented C++17 solution

An independently written complete program with standard headers.

#include<iomanip>
#include<iostream>
using namespace std;
int main(){
    int hour,minute,registration,travelHour,travelMinute,pupils,hotel;
    cin>>hour>>minute>>registration>>travelHour>>travelMinute>>pupils>>hotel;
    // The official samples include hotel check-in for the leader.
    int departure=hour*60+minute-registration;
    departure-=travelHour*60+travelMinute;
    departure-=(pupils+1)*hotel+10;
    cout<<setfill('0')<<setw(2)<<departure/60<<' ';
    cout<<setw(2)<<departure%60<<'\n';
}

Source: Arena Olimpiici ↗