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 E2009 · EasyArithmetic

Biathlon

Autumn Tournament (2009)

Submission name: biathlon.cpp

Problem summary

Three biathletes A, B, and C have skiing times and five shots each. Every missed shot adds 30 seconds. Find the athlete with the smallest adjusted time and print that time in minutes and seconds. Adjusted times are distinct.

Input

Three lines for A, B, C respectively, each containing minutes m, seconds s, and successful shots i.

Output

The winner’s adjusted minutes and seconds, then their letter, separated by spaces.

Constraints

1 ≤ m ≤ 1000000000000; 0 ≤ s < 60; 0 ≤ i ≤ 5. No tied adjusted times.

Worked example

Original statement sample.

Input

4 33 4
3 56 3
4 48 5

Output

4 48 C

Solution analysis

  1. Convert each skiing time to seconds as 60m + s. The number of misses is 5 − i, so add 30(5 − i).
  2. Keep the smallest adjusted total and its athlete index. Convert the winning total back using division by 60 for minutes and remainder by 60 for seconds.
  3. In the sample A has 303 seconds after penalties, B has 296, and C has 288. Thus C wins with 4 minutes 48 seconds.

Why it works

The conversion and penalty formula give each athlete’s true adjusted time in the same unit. The running minimum selects the least of the three, and division with remainder represents that same time in minutes and seconds.

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

Watch out. The third input value counts hits, not misses. Use 64-bit arithmetic because m can be 10^12. Include penalties in the printed time.

Commented C++17 solution

An independently written complete program with standard headers.

// Key idea: The conversion and penalty formula give each athlete’s true adjusted time in the same
// unit. The running minimum selects the least of the three, and division with remainder represents
// that same time in minutes and seconds.
#include<algorithm>
#include<iostream>
#include<limits>
#include<string>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    long long bestTime=numeric_limits<long long>::max();
    int winner=0;
    for(int athlete=0;athlete<3;athlete++){
        long long minutes;
        int seconds,hits;
        cin>>minutes>>seconds>>hits;
        long long adjusted=60*minutes+seconds+30*(5-hits);
        if(adjusted<bestTime){
            bestTime=adjusted;
            winner=athlete;
        }
    }
    cout<<bestTime/60<<' '<<bestTime%60<<' ';
    cout<<static_cast<char>('A'+winner)<<'\n';
}

Source: Arena Olimpiici ↗