crowulll

Untitled

Aug 3rd, 2020
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.44 KB | None | 0 0
  1. #include<iostream>
  2. #include<vector>
  3. #include<cmath>
  4. using namespace std;
  5. long long n, c, p;
  6. int main(){
  7.     cin >> n;
  8.     vector <long long> a(n + 1); c = 0; p = 1; bool zero = false;
  9.     for (long long i = 1; i < n + 1; ++i){
  10.         cin >> a[i];
  11.         c += abs(abs(a[i]) - 1);
  12.         if (a[i] < 0) p *= -1;
  13.         if (a[i] == 0) zero = true;
  14.     }
  15.     if (p == 1) cout << c;
  16.     else if (zero) cout << c;
  17.     else cout << c + 2;
  18.  
  19. }
Advertisement
Add Comment
Please, Sign In to add comment