Advertisement
Jakube

Untitled

May 1st, 2020
589
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.99 KB | None | 0 0
  1. from dataclasses import dataclass
  2.  
  3.  
  4. def read_ints():
  5.     return list(map(int, input().split()))
  6.  
  7.  
  8. @dataclass
  9. class Truck:
  10.     s: int
  11.     f: int
  12.     c: int
  13.     r: int
  14.  
  15.  
  16. def check(trucks, M, cities):
  17.     for truck_idx, truck in enumerate(trucks):
  18.         remaining = truck.r
  19.         V = M;
  20.         rel_cities = cities[truck.s-1:truck.f]
  21.         for city1, city2 in zip(rel_cities, rel_cities[1:]):
  22.             needed = (city2 - city1) * truck.c
  23.             if V >= needed:
  24.                 V -= needed
  25.             elif remaining and M >= needed:
  26.                 V = M - needed
  27.                 remaining -= 1
  28.             else:
  29.                 return truck_idx
  30.  
  31.  
  32. n, m = read_ints()
  33. cities = read_ints()
  34. trucks = [Truck(*read_ints()) for _ in range(m)]
  35.  
  36. L = 0  # not possible
  37. R = 10**18  # possible
  38. while L + 1 < R:
  39.     M = L + max(1, (R - L) // 2000)
  40.     if (res := check(trucks, M, cities)) is None:
  41.         R = M
  42.     else:
  43.         L = M
  44.         trucks = trucks[res:]
  45. print(R)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement