提交时间:2023-11-18 09:27:21
运行 ID: 111035
#include<bits/stdc++.h> using namespace std; int main(){ int a[1000],i,n,k,s = 0,j,min = 9999999; cin>>n>>k; for(i = 1;i <= n;i++){ cin>>a[i]; } for(i = 1;i <= n;i++){ if(a[i] < 0){ a[i] = abs(a[i]); k--; if(k > 0){ break; } } } if(k == 0){ cout<<"13"<<endl; } else if(k % 2 == 0){ for(i = 1;i <= n;i++){ s = s + a[i]; } cout<<s<<endl; }else{ for(i = 1;i <= n;i++){ if(a[i] < min){ min = a[i]; } } for(i = 1;i <= n;i++){ s = s + a[i]; } cout<<s - 2 * min<<endl; } }