题解 | 小苯送礼物

小苯送礼物

https://www.nowcoder.com/practice/466e02d2177845589ab5fa5decc2857f

while True:
    try:
        n, k = map(int, input().split())
        support_list = []
        for i in range(n):
            star, collect = map(int, input().split())
            # 编号,支持力度,收藏数
            support_list.append([i+1, 1*star+2*collect, collect])
        # print(support_list)
        # 按照支持力度逆序,收藏数逆序,编号正序排列
        support_list_sorted = sorted(support_list, key=lambda x: (-x[1], -x[2], x[0]))
        # print(support_list_sorted)
        number_list = []
        for j in range(k):
            number_list.append(support_list_sorted[j][0])
        print(' '.join(str(num) for num in sorted(number_list)))
    except Exception as e:
        break

全部评论

相关推荐

开发转测第二人:没实习的话,两个项目吧,八股也要准备一下,这个时间点有点小晚了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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