提交时间:2023-11-18 08:55:55
运行 ID: 110994
#include<bits/stdc++.h> using namespace std; int a[114514]; signed main(){ int n,k; cin>>n>>k; for (int i = 1;i <= n;i++){ cin>>a[i]; } sort(a + 1,a + n + 1); for (int i = 1;i <= n;i++){ if (k == 0){ break; } if (a[i] < 0){ k--; k %= 2; a[i] = -a[i]; } else{ if (k & 1){ k--; a[i] = -a[i]; } k %= 2; } } int sum = 0; for (int i = 1;i <= n;i++){ sum += a[i]; } cout<<sum; return 0; }