提交时间:2023-11-18 10:26:59
运行 ID: 111101
#include<bits/stdc++.h> using namespace std; int nums[1010]; int main(){ int n,k; scanf("%d %d",&n,&k); for(int i = 1;i <= n;i++){ scanf("%d",&nums[i]); } sort(nums+1,nums+n+1); for(int i = 1;i <= k;i++){ if(nums[i] == 0){ break; } nums[i] = nums[i]- (2*nums[i]); } int sum = 0; for(int i = 1;i <= n;i++){ sum+=nums[i]; } printf("%d",sum); return 0; }