商汤-智慧商业-算法笔试1.2题

居然能ac,有点怀疑。。
第一题:
n,c = map(int,input().rstrip().split())
nlist = list(map(int,input().rstrip().split()))
nlist.sort(reverse=True)
res = 0
i=0
while i < n:
    res += nlist[i]
    i += c
print(res)
第二题:
n = int(input().rstrip())
Xi = list(map(int,input().rstrip().split()))
Xi.sort()
count = 0
for i in range(n):
    count += abs(Xi[i]-i-1)
print(count)




#笔试题目##商汤科技##算法工程师#
全部评论
题目是啥
点赞 回复
分享
发布于 2019-08-19 21:50

相关推荐

点赞 评论 收藏
转发
2 2 评论
分享
牛客网
牛客企业服务