题解 | 支付宝消费打折

支付宝消费打折

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

全部评论

相关推荐

01-02 20:08
马鞍山学院 Java
27届学院本誓死冲击...:实习经历最好写上做了什么项目,负责什么业务,否则有点假
点赞 评论 收藏
分享
狸猫换offer:神通广大的互联网
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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