牛客竞赛
自用, 便于复制
for(let T = parseInt(readline()); T > 0; T--) {
const [n, m] = readline().split(' ', 2).map(v => parseInt(v));
const nums = readline().split(' ', n).map(v => parseInt(v));
let sum = 0;
const sub = [];
for(const i in nums) {
sum += nums[i];
(v => v > 0 && sub.push(v))(nums[i] * (nums.length - i));
}
sub.sort((a, b) => b - a);
sub.slice(0, Math.min(m, sub.length)).forEach(v => sum -= v);
print(sum);
}
标签:const,sub,nums,sum,牛客,parseInt,readline,模板,刷题
From: https://www.cnblogs.com/xtyuns/p/17498378.html