商汤-智慧商业-算法笔试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

相关推荐

牛客38347925...:9,2学生暑期实习失利开始投小厂,给这群人整自信了
点赞 评论 收藏
分享
_mos_:忍耐王
点赞 评论 收藏
分享
大飞的诡术妖姬:之前看b站多明海有个说法,日本就业竞争非常低的原因不光是毕业学生少,还有很多人干两年不喜欢职场氛围就辞职躺平,位置也空了很多,论吃苦耐劳还得看咱们
点赞 评论 收藏
分享
评论
2
2
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务