• 1
    Input and Output Data
    • Tasks
  • 2
    Conditions
    • Tasks
  • 3
    For Loop
    • Tasks
  • 4
    Strings
    • Tasks
  • 5
    While Loop
    • Tasks
  • 6
    Lists
    • Tasks
  • 7
    Two-Dimensional Arrays
    • Tasks
  • 8
    Dictionaries
    • Tasks
  • 9
    Sets
    • Tasks
  • 10
    Functions and Recursion
    • Tasks
  • к

Занятие 6. Lists

Difficulty level:

Task«The queue in the supermarket»

You work in a supermarket and you need to optimize the work of the box office. During the day, a different number of buyers is suitable for the cash desks, and each of them spends different times on scanning and paying for their purchases. Your task is to calculate how much time it will take to serve all buyers if they are distributed at the cash desks.

Input format

customers -a list of natural numbers representing the time that each client spends on ordering an order. & nbsp; Clients.
rn
cash desks -a natural number that is the number of cash desks

Output format

The total time required to serve all customers

Example

Input

[5, 3, 4]
2 & nbsp;

Output

6

Hint

There will be no clue here, decide for yourself!

main.py
Test 1
Test 2
Test 3
Test 4
Test 5
Test 6
Test 7
Test 8
Test 9
Test 10
Developer’s solution
import heapq

# Ввод данных
clients = [int(c) for c in input().strip('[]').split(',') if c.strip().isdigit()]
num_counters = int(input())
# Если список клиентов пустой, выводим 0
if not clients:
    print(0)
else:
    # Создаем список для касс (время обслуживания на каждой), изначально 0
    counters = [0] * num_counters
    heapq.heapify(counters)  # Преобразуем в кучу

    # Распределяем клиентов по кассам
    for time in clients:
        current = heapq.heappop(counters)  # Берем кассу с минимальным временем
        current += time  # Добавляем время клиента
        heapq.heappush(counters, current)  # Возвращаем в кучу

    # Выводим максимальное время среди касс
    print(max(counters))

🎉 Congratulations! 🎉

You did an excellent job with the task! It was a challenging problem, but you found the correct solution. You are one step closer to mastering programming! Keep up the good work, because every stage you pass makes you even stronger.

AD

Advertisement

red-snake blue-snake green-snake

Running your code...

Помощник ИИ

Привет! Я твой помощник по программированию. Задавай любые вопросы по Python, я могу рассказать о функциях, методах, обьяснить то, что тебе не понятно, а так же о текущей задаче!