Advertisement
Pastehsjsjs

Untitled

Jun 7th, 2023
791
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.51 KB | Source Code | 0 0
  1. with open('/Users/alex26/Downloads/26 (18).txt', 'r') as f:
  2.     _, K, M = [int(f.readline()) for _ in range(3)]
  3.     d = list(map(int, f.read().strip().split('\n')))
  4.     d.sort(reverse=True)
  5.     space = [M for _ in range(K)]
  6.  
  7. last_idx = -1
  8. while True:
  9.     last_idx += 1
  10.     if last_idx == len(space) or not d:break
  11.     d.sort(reverse=True)
  12.     to_del = []
  13.     for i in d.copy():
  14.         if space[last_idx] - i >= 0:
  15.             space[last_idx] -= i
  16.             d.remove(i)
  17.  
  18. print(last_idx, space[last_idx - 1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement