def solution(team,n):
a = 0
b = 0
if n==1:
for i in range(len(team)):
a=a+team[i]
return a
else:
a = team[0]
b = team[n-1]
for i in range(2,len(team)):
if a-b>0:
b=b+team[i]
else:
a=a+team[i]
if a>b:
return a
else:
return b
assert solution([5,3,4], 1) == 12
assert solution([10,2,3,3], 2) == 10
assert solution([2,3,10], 2) == 12
def solution(nums: list, n: int)-> int:
nlist = []
#初始化排队口
for i in range(n):
nlist.append(0)
for num in nums:
nlist[nlist.index(min(nlist))] += num
return max(nlist)
#果然想复杂了呢哎
def solution(nums: list, n: int)-> int:
# your code here
ent = nums[:n]
T = 0
for i in nums[n:]:
minnest = min(ent)
T += minnest
for index,value in enumerate(ent):
ent[index] = value - minnest
if ent[index] == 0:
ent[index] += i
return T + max(ent)
assert solution([5,3,4], 1) == 12
assert solution([10,2,3,3], 2) == 10
assert solution([2,3,10], 2) == 12
assert solution([10,2,3,3,12], 2) == 20
def solution(nums: list, n: int)-> int:
if len(nums)==0:return 0
if 0<len(nums)<=n:
return max(nums)
else:
queue = [nums[i] for i in range(n)]
queue.sort(reverse=True)
for i in range(n,len(nums)):
queue[n-1] +=nums[i]
#排序
tmp=queue[n-1]
left=n-2
while left>=0 and queue[left]<tmp:
queue[left + 1] = queue[left]
left -= 1
queue[left + 1] = tmp
return queue[0]