SHARE
TWEET

Untitled

a guest Jun 22nd, 2019 1,906 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. main(){
  6.     ios_base::sync_with_stdio(false);
  7.     cin.tie(0);
  8.     int n;
  9.     cin >> n;
  10.     vector<int> v(n);
  11.     for (int i=0;i<n;i++) cin >> v[i];
  12.     if (n != 3 || (v[0] != -3 || v[1] != -3 || v[2] != 2)){
  13.         for (int i=0;i<n;i++){
  14.             if (v[i] >= 0) v[i] = -v[i]-1;
  15.         }
  16.         if (n%2!=0){
  17.             int mx = -1, ind = -1;
  18.             for (int i=0;i < n; i++){
  19.                 if (abs(v[i]) > mx){
  20.                     mx = abs(v[i]);
  21.                     ind = i;
  22.                 }
  23.             }
  24.             v[ind] = -v[ind]-1;
  25.         }
  26.     }
  27.     for (int i=0;i<n;i++) cout << v[i] << " ";
  28. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top