-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrades.py
More file actions
41 lines (31 loc) · 1 KB
/
grades.py
File metadata and controls
41 lines (31 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python3
# 2016 South Central USA, problem 7997
def get_max(grade_str, amt):
if amt == 1:
if grade_str == '' or int(grade_str) > 100:
raise Exception('invalid grade')
return int(grade_str)
possible_results = []
if grade_str[:3] == '100':
try:
possible_results.append(int(grade_str[:3]) +
get_max(grade_str[3:], amt - 1))
except:
pass
try:
possible_results.append(int(grade_str[:2]) +
get_max(grade_str[2:], amt - 1))
except:
pass
try:
possible_results.append(int(grade_str[:1]) +
get_max(grade_str[1:], amt - 1))
except:
pass
return max(possible_results)
def get_max_avg(grade_str, amt):
return round(get_max(grade_str, amt) / amt)
students = int(input())
for i in range(students):
amt, grade_str = input().split(' ')
print(get_max_avg(grade_str, int(amt)))