提交时间:2023-11-18 08:51:26
运行 ID: 110987
#include<bits/stdc++.h> using namespace std; int a[1005]; int main(){ int n, k; cin >> n >> k; for (int i = 1; i <= n; i++){ cin >> a[i]; } int minx = 1000, ii = 0; while (k > 0){ for (int i = 1; i <= n; i++){ minx = min(minx, a[i]); if (a[i] == minx){ ii = i; } } a[ii] = -a[ii]; k --; } int sum = 0; for (int i = 1; i <= n; i++){ sum += a[i]; } cout << sum; return 0; }