When the Game Starts
Autumn Tournament (2025)
Submission name: VCD.cpp
Problem summary
Three friends start homework on the same day at different times. Each solves c problems, spending mm minutes and ss seconds on each, then rests for ten minutes before joining an online game. The game begins when the last friend joins. Find its time of day.
Input
Three lines of h m s c mm ss, one per friend.
Output
Hour, minute and second of the game start, separated by spaces. Midnight is 0 0 0.
Constraints
0 ≤ h < 24; 0 ≤ m,s,mm,ss < 60; 1 ≤ c ≤ 50.
Worked example
The example is reproduced from the original tournament statement.
Input
19 45 0 9 25 30 12 0 0 18 39 59 20 15 45 5 59 59
Output
1 25 40
Solution analysis
- Convert each start to seconds since the beginning of the common day. Add c(60mm+ss) seconds of work and 600 seconds of rest.
- Take the maximum of these elapsed times before reducing modulo 86400. Taking the maximum after wrapping could incorrectly treat a next-day arrival as earlier. Decode the maximum remainder into hours, minutes and seconds.
- In the sample, arrivals are 23:44:30, next-day 00:09:42 and next-day 01:25:40. The third elapsed arrival is largest, so the game starts at 1 25 40.
Why it works
Each computed arrival equals its start plus all work and rest. Since all starts refer to the same day, the maximum elapsed arrival is exactly when all friends are present. Reducing that maximum by complete days changes only its date, giving the required clock time.
Watch out. Add the ten-minute break for every friend. Compare full elapsed times before applying the daily modulo.
Commented C++17 solution
An independently written complete program with standard headers.
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
int latest=0;
for(int i=0;i<3;i++){
int h,m,s,count,minutes,seconds;
cin>>h>>m>>s>>count>>minutes>>seconds;
int arrival=h*3600+m*60+s;
arrival+=count*(minutes*60+seconds)+600;
latest=max(latest,arrival);
}
// Wrap only after choosing the chronologically latest arrival.
latest%=86400;
cout<<latest/3600<<' '<<latest/60%60;
cout<<' '<<latest%60<<'\n';
}