提交时间:2023-11-18 08:46:51
运行 ID: 110982
#include <bits/stdc++.h> using namespace std; int n , k; int sum; int a[1005]; int mi() { int minn = 2147483647; int t; for(int i = 1;i <= n;i++) { if(a[i] < minn) { minn = a[i]; t = i; } } return t; } int sum1() { for(int i = 1;i <= n;i++) sum += a[i]; return sum; } int main() { cin >> n >> k; for(int i = 1;i <= n;i++) cin >> a[i]; for(int i = 1;i <= k;i++) { int t = mi(); a[t] = 0 - a[t]; } cout << sum1(); return 0; }