class Solution {
public:intlargestSumAfterKNegations(vector<int>& nums,int k){sort(nums.begin(), nums.end());int pre = nums[0];//记录绝对值最小的数int result =0;for(int i =0; i < nums.size(); i++){if(k >0&& nums[i]<0){
k--;
nums[i]*=-1;
pre = nums[i];}elseif(k >0&& nums[i]==0){
k =0;}// 绝对值最小的一定是在这或前一个数elseif(k >0&& nums[i]>0){if(k %2!=0){
pre =min(nums[i], pre);
result -=2*pre;}
k =0;}
result += nums[i];}if(k >0&& k %2!=0){
result -=2*pre;}return result;}};