scripts/ege/28.03.2023 ПРОБНИК/Faily_IN11_28032023_/26.py

32 lines
710 B
Python
Raw Normal View History

2023-05-05 00:45:01 +03:00
with open("26.txt") as f:
data = [list(map(int, x.split())) for x in f.read().splitlines()]
res = []
rows = {}
for el in data[1:]:
if el[0] in rows:
rows[el[0]] += [el[1]]
else:
rows[el[0]] = [el[1]]
for elll, row in rows.items():
row = sorted(row)
if len(row) > 1:
c = 0
for i in range(1, len(row)):
i1 = row[i - 1]
i2 = row[i]
if i2 - i1 <= 9:
c += i2 - i1
else:
if c:
res.append((elll, c))
c = 0
if c:
res.append((elll, c))
print(sorted(res, key=lambda x: x[1], reverse=True)[:20])