int main() { vector<int> nums={23,376,205,132,19,61,190,398,29,4,18,40}; sort(nums.begin(),nums.end()); int res=0; int tmp=0; int target=100; while(nums.size()>0){ tmp=0; for(int i=0;i<nums.size();i++){ if(abs(nums[tmp]-target)>abs(nums[i]-target)){ tmp=i; } } res+=(abs(target-nums[tmp])); target=nums[tmp]; nums.erase(nums.begin()+tmp); } return 0; }