classSolution:defbestTeamScore(self, scores: List[int], ages: List[int])->int:
n =len(scores)
nums =sorted(zip(scores, ages))
f =sorted(scores)for i inrange(n):for j inrange(0, i):if nums[j][1]<= nums[i][1]:
f[i]=max(f[i], f[j]+ nums[i][0])returnmax(f)
背单词的小智(二分 + 贪心)
n, k =map(int,input().split())
a =list(map(int,input().split()))
s =[0]*(n +1)for i inrange(n):
s[i +1]= s[i]+ a[i]**2defcheck(x):
res =0
i =0while i < n:
start = i
if s[start +1]- s[start]> x:returnFalse
i +=1while i < n and s[i +1]- s[start]<= x:
i +=1
res +=1return res <= k
l, r =0, s[n]- s[0]while l < r:
mid =(l + r)>>1if check(mid):
r = mid
else:
l = mid +1print(l)