1670. 回合制游戏

1670. 回合制游戏

CAT 专属题目
中文English

QW 是一个回合制游戏的玩家,今天他决定去打怪。

QW 在一场战斗中会碰到 n 个怪物,每个怪物有攻击力 atk[i],每回合结束时如果第 i 个怪物还活着,就会对 QW 造成 atk[i] 的伤害。QW 只能在每回合开始时击杀一个怪物,请帮 QW 出他打完所有怪物最少需要损失多少生命值。

样例

样例 1:

输入:atk = [19,3]
输出:3

样例 2:

输入:atk = [1,3,2,5]
输出:10

注意事项

n, atk[i] <= 100000
答案可能超过 int 范围 

输入测试数据 (每行一个参数)如何理解测试数据?
class Solution:
    """
    @param atk: the atk of monsters
    @return: Output the minimal damage QW will suffer
    """
    def getAns(self, atk):
        # Write your code here
        #每次击杀最大值
        atk.sort()
        atk_total = 0 
        length = len(atk)
        cur_atk = 0
        
        for i in range(length - 1):
            cur_atk = cur_atk + atk[i]
            atk_total += cur_atk
        
        return atk_total
              
原文地址:https://www.cnblogs.com/yunxintryyoubest/p/13512182.html