Grades
Time limit1sMemory limit1024 MB
Insert Juku into a presentation order to maximize the grades he receives, where grades either reflect project value or reciprocate a prior grade.
- Level
Medium7 of 10
- Topics
- Greedy, Prefix sum, Math
- Solved
- No attempts yet
Problem
Every student in a class must present their own research project. After each presentation, every other student gives the presented project a grade.
Student grades student 's project according to the following rule:
- If has not yet graded 's project, then gives an honest grade equal to the actual value of 's project.
- If has already graded 's project, then returns exactly the same grade that received from .
The teacher has already written a list fixing the order of all presentations, but Juku's name is missing from it. Determine at which position in the list Juku should insert himself so that the total grade he receives is maximized. The student currently at Juku's chosen position and everyone after them shift one place back in the order.
Input
The first line contains the value of Juku's research project ().
The second line contains the number of students already on the list ().
Each of the next lines contains the value of one student's research project ().
Output
Print two integers on one line. The first is the maximum total grade Juku can receive; the second is the position in the list he must choose to achieve it. The position ranges from to , where means standing after everyone. If several positions achieve the maximum, print the smallest (earliest) one.