""" K 件物品的最大和 """ class Solution: def kItemsWithMaximumSum(self, numOnes: int, numZeros: int, numNegOnes: int, k: int) -> int: if k <= numOnes: return k elif numOnes < k <= (numOnes + numZeros): return numOnes elif (numOnes + numZeros) < k <= (numOnes + numZeros + numNegOnes): return numOnes - (k - numOnes - numZeros) else: return numOnes - numNegOnes return result if __name__ == '__main__': result = Solution().kItemsWithMaximumSum(3, 2, 0, 2) print(result)