题解 | 支付宝消费打折

支付宝消费打折

https://www.nowcoder.com/practice/f8997c9b82714f058e12433a32614993

while True:
    try:
        n, k = map(int, input().split())
        # print(n, k)
        price = map(int, input().split())
        low_price = list(int(i) for i in input())
        info_list = list(zip(price, low_price))
        # print(info_list)
        price_list = []
        for info in info_list:
            if info[1] == 1:
                price = info[0] * 95 / 100
                price_list.append(price)
            else:
                price = info[0]
                price_list.append(price)
        # 将优惠后的价格从低到高排序,这样就可以算出最多能买多少件物品
        # print(sorted(price_list))
        s = 0
        count = 0
        for price in sorted(price_list):
            # 判断加上这个物品是否不超过预算,不要直接s <= k
            if s + price <= k:
                s += price
                count += 1
            else:
                break
            # print(price)
        print(count)


    except Exception as e:
        break

全部评论

相关推荐

许愿一个offer_...:不是啊,这个只代表你的面试官提交了你的面评,面试是否通过还是要看官网状态呢
腾讯2025实习生招聘
点赞 评论 收藏
分享
05-23 19:33
重庆大学 Java
只学了传统后端,马上去后端实习了,在想要不要学习agent开发相关的。27秋招和26相比难度如何?
我连备胎都不是却还在...:就暑期实习而言,大厂官宣hc 比 26 多,但是我观察看应该低于 26 的,估计秋招也不简单
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务