Advertisement
Pastehsjsjs

Untitled

Apr 18th, 2023
778
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.56 KB | Source Code | 0 0
  1. with open('/Users/alex26/Downloads/26.txt', 'r') as f:
  2.     x = [[int(i.split()[0]), int(i.split()[1])] for i in f.read().strip().split('\n')]
  3.     x.sort() #почему если заменить x.sort() на x.sort(key=lambda x: x[0]) будет не правильный ответ
  4. M = 100
  5.  
  6. cells = [0 for i in range(M)]
  7.  
  8. k = 0
  9. for i in x:
  10.     for cell_index in range(len(cells)):
  11.         if i[0] > cells[cell_index]:
  12.             cells[cell_index] = i[1]
  13.             k += 1
  14.             last_index = cell_index
  15.             break
  16.  
  17. print(k, last_index + 1)
  18.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement