The Supermarket Queue----codewar刷题总结

本文总结了在Codewars上关于超市结账队列问题的解题经验,探讨了如何计算所有顾客结账所需的总时间。问题涉及到单一队列服务多个收银台的情况,强调了队列顺序不变且首位顾客在收银台空闲时立即结账的原则。文章介绍了两种解决方案,一种是通过列表操作实现,另一种则是利用堆数据结构的heapq模块进行优化。
摘要由CSDN通过智能技术生成

thanks a lot for codewar

Description:

There is a queue for the self-checkout tills at the supermarket. Your task is write a function to calculate the total time required for all the customers to check out!

input

  • customers: an array of positive integers representing the queue. Each integer represents a customer, and its value is the amount of time they require to check out.
  • n: a positive integer, the number of checkout tills.

output

The function should return an integer, the total time required.


Important

Please look at the examples and clarifications below, to ensure you understand the task correctly :)


Examples

queue_time([5,3,4], 1)
# should return 12
# because when n=1, the total time is just the sum of the times

queue_time([10,2,3,3], 2)
# should return 10
# because here n=
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值