def do_tre(thoi_gian_xu_ly, moc_den=None): ket_thuc = 0 do_tre_ms = [] for i, xu_ly in enumerate(thoi_gian_xu_ly): den = ket_thuc if moc_den is None else moc_den[i] ket_thuc = max(den, ket_thuc) + xu_ly do_tre_ms.append(ket_thuc - den) return do_tre_ms xu_ly = [500, 20, 20, 20] tai_mo = do_tre(xu_ly, [0, 100, 200, 300]) tai_dong = do_tre(xu_ly) assert tai_mo == [500, 420, 340, 260] assert tai_dong == [500, 20, 20, 20] print("Tải mở", tai_mo, "| Tải đóng", tai_dong)