zhukov000

26_example

Feb 7th, 2022
984
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.66 KB | None | 0 0
  1. a = dict()
  2. with open("26-71.txt") as file:
  3.   n, s = map(int, file.readline().split())
  4.   for row in file:
  5.     t, v = map(int, row.split())
  6.     if t not in a:
  7.       a[t] = []
  8.     a[t].append(v)
  9.  
  10. """
  11.  a[тип1] = [товар1, товар2 ...]
  12.  a[тип2] = [товар1, товар2 ...]
  13.  ...
  14. """
  15. total_k = 0
  16. mx_k = 0
  17. code = 0
  18. for t in a.keys(): # a.keys() - ключи словаря - типы товаров
  19.   lst = a[t]
  20.   lst.sort()
  21.   sum_t = 0
  22.   k_t = 0
  23.   for v in lst:
  24.     if sum_t + v <= s:
  25.       sum_t += v
  26.     else:
  27.       k_t += 1
  28.   total_k += k_t
  29.   if k_t > mx_k:
  30.     mx_k = k_t
  31.     code = t
  32. print(total_k, code)
  33.      
  34.  
  35.    
  36.  
  37.  
Advertisement
Add Comment
Please, Sign In to add comment