forked from SaruarChy/Codeforces-Solution
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1206 B. Make Product Equal One.cpp
49 lines (46 loc) · 1.07 KB
/
1206 B. Make Product Equal One.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
using namespace std;
int main()
{
fastread();
int n,a[100001];
ll sum = 0;
int pos = 0,neg = 0,zero = 0,k = 0;
cin>>n;
for(int i=0; i<n; i++){
cin>>a[i];
}
//sort(a,a+n);
for(int i=0; i<n; i++){
if(a[i] == 1 || a[i] == -1)continue;
else if(a[i] < -1){
sum += abs(a[i] + 1);
a[i] -= (a[i] + 1);
}
else if( a[i] > 1){
sum += a[i] - 1;
a[i] = 1;
}
}
for(int i=0; i<n; i++){
if(a[i] == 0){
zero++;
a[i] = 1;
}
else if(a[i] == -1)neg++;
else if(a[i] == 1)pos++;
}
sum += zero;
pos += zero;
//zero = 0;
if(neg % 2 == 1){
if(zero > 0)pos--;
else sum+=2;
}
cout<<sum<<endl;
}