Grade Conversion 2
InterviewTime limit2sMemory limit1024 MB
Given the new grades b, recover old grades a that produce them under the averaging rule, or print -1 if no such sequence exists.
- Level
Medium5 of 10
- Topics
- Prefix sum, Greedy
- Solved
- No attempts yet
Problem
Until the 2023 academic year, Daegu Science High School gave each student a semester grade, an integer from to , based on that semester's performance. A lower number meant a better grade, so was the best and was the worst. This system did not reflect how much a student improved from the previous semester, so students focused on their rank relative to others instead of their own growth.
Starting in the 2024 academic year, the school changed the rule. If a student's grade was lower than the average of their earlier grades, the grade was reduced by . Specifically, let be the grades for semesters through under the old system, which was in use through the 2023 academic year. Then the grades are computed as follows.
- For each , if , then . Otherwise, .
Under this definition, grades from the 2024 academic year onward are always integers from to .
Input
The first line contains , the number of semesters Eunseong attended.
The second line contains Eunseong's grades .
Output
Print the old-system grades separated by spaces. If several sequences satisfy the conditions, print any one of them. If no such sequence exists, print instead.
Constraints
- For each ,
- All given numbers are integers.