nicuvlad76

1877

Oct 25th, 2020
503
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<bits/stdc++.h>
  2. #define N 1005
  3. using namespace std;
  4.  
  5. int n,v[N],k;
  6.  
  7. int main()
  8. {
  9.     int s=0;
  10.     cin>>n;
  11.     for(int i=1; i<=n; i++)
  12.        cin>>v[i];
  13.     cin>>k;
  14.  
  15.     sort(v+1,v+n+1);
  16.  
  17.     for(int i=1;i<=k;i++)
  18.         v[i]=-v[i];
  19.  
  20.     for(int i=1;i<=n;i++)
  21.         s+=v[i];
  22.     cout<<s;
  23.     return 0;
  24. }
  25.  
RAW Paste Data