inFile = open('input.txt', 'r', encoding='utf8')
outFile = open('output.txt', 'w', encoding='utf8')
score = []
i = 0
nstr = 1
for line in inFile:
if nstr == 1:
k = int(line)
else:
line1 = line.split()
sc3 = int(line1[-1])
sc2 = int(line1[-2])
sc1 = int(line1[-3])
if sc1 >= 40 and sc2 >= 40 and sc3 >= 40:
score.append(sc1 + sc2 + sc3)
i += 1
nstr += 1
inFile.close()
if k >= i:
print(0, file=outFile)
score.sort(reverse=True)
if score[k-1] > score[k]:
print(score[k-1], file=outFile)
ans = ''
for ii in score[k-1::-1]:
if score[k-1] < ii and ans == '':
ans = ii
if ans == '':
ans = 1
print(ans, file=outFile)
outFile.close()
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Table</title>
</head>
<body>
<table border="1">
<tr>
<td rowspan="3">day</td>
<td colspan="3">seminar</td>
</tr>
<td colspan="2">schedule</td>
<td rowspan="2">topic</td>
<td>begin</td>
<td>end</td>
<td>monday</td>
<td>8</td>
<td>5</td>
<td>introduction to xml</td>
<td rowspan="3">tuesday</td>
<td>11</td>
<td>xpath</td>
<td>2</td>
<td rowspan="2">xsl</td>
<td>w</td>
<td>12</td>
<td>xsl</td>
</table>
</body>
</html>
inFile = open('input.txt', 'r', encoding='utf8')
outFile = open('output.txt', 'w', encoding='utf8')
score = []
i = 0
nstr = 1
for line in inFile:
if nstr == 1:
k = int(line)
else:
line1 = line.split()
sc3 = int(line1[-1])
sc2 = int(line1[-2])
sc1 = int(line1[-3])
if sc1 >= 40 and sc2 >= 40 and sc3 >= 40:
score.append(sc1 + sc2 + sc3)
i += 1
nstr += 1
inFile.close()
if k >= i:
print(0, file=outFile)
else:
score.sort(reverse=True)
if score[k-1] > score[k]:
print(score[k-1], file=outFile)
else:
ans = ''
for ii in score[k-1::-1]:
if score[k-1] < ii and ans == '':
ans = ii
if ans == '':
ans = 1
print(ans, file=outFile)
outFile.close()
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Table</title>
</head>
<body>
<table border="1">
<tr>
<td rowspan="3">day</td>
<td colspan="3">seminar</td>
</tr>
<tr>
<td colspan="2">schedule</td>
<td rowspan="2">topic</td>
</tr>
<tr>
<td>begin</td>
<td>end</td>
</tr>
<tr>
<td>monday</td>
<td>8</td>
<td>5</td>
<td>introduction to xml</td>
</tr>
<tr>
<td rowspan="3">tuesday</td>
<td>8</td>
<td>11</td>
<td>xpath</td>
</tr>
<tr>
<td>11</td>
<td>2</td>
<td rowspan="2">xsl</td>
</tr>
<tr>
<td>2</td>
<td>5</td>
</tr>
<tr>
<td>w</td>
<td>8</td>
<td>12</td>
<td>xsl</td>
</tr>
</table>
</body>
</html>