SAC '21 Code Challenge P3 - DeMello's Replacement

View as PDF

Submit solution


Points: 5
Time limit: 1.0s
Memory limit: 256M

Authors:
Problem type

Mr. DeMello wants to find a replacement for himself before retiring. He has determined how to score them and uses the equation S = 4 \times \sqrt{M} + 3 \times {CS}^P - 4 \times E, where M is the student's math grade, CS is the student's computer science grade, E is the student's English grade, and P is an integer of Mr. DeMello's choice. Given N students, Mr. DeMello wants you to determine the student with the highest score and the student with the lowest score rounded down to the closest integer.

Input Specification

The first line will consist of a positive integer N (2 \le N \le 100\,000) and P (0 \le P \le 5).

The next N lines will consist of the name of the i^\text{th} student (with no spaces between characters) and their math (0 \le M \le 100), computer science (0 \le CS \le 100), and English mark (0 \le E \le 100) separated by a space.

Note: The maximum and minimum scores will be distinct from every other score (even after rounding down), and P and CS will not both be 0.

Output Specification

On the first line of output, output the name of the student with the highest score followed by their score S, separated by a space and rounded down to the closest integer.

On the second line of output, output the name of the student with the lowest score followed by their score S, separated by a space and rounded down to the closest integer.

Sample Input

3 2
Zain 98 99 96
Max 92 100 2
Ethan 34 57 58

Sample Output

Max 30030
Ethan 9538

Comments


  • 19
    noirsnow  commented on May 6, 2021, 4:53 a.m. edited

    Note that directly using int to floor will cause the float to be rounded towards 0.(At least for me in python) In other words,

    int(2.1) >> 2
    math.floor(2.1) >> 2 
    int(-2.1) >> -2 (rounded up)
    math.floor(-2.1) >> -3

    This caused me to be stuck in the contest trying different ways of changing the equation to some form... :( At least I learned a lesson today