-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path1206B Make Product Equal One.cpp
59 lines (54 loc) · 1.03 KB
/
1206B 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
50
51
52
53
54
55
56
57
58
59
/*
Author : MishkatIT
Created : Tuesday 02-07-2024 22:49:14
*/
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif
using ll = long long;
using ld = long double;
const ll mod = 1e9 + 7;
const ll N = 2e5 + 10;
const ll inf = 1e9;
const ll linf = 1e18;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
vector<int> v(n);
for (auto& i : v) {
cin >> i;
}
ll ans = 0;
for (auto& i : v) {
if (i > 1) {
ans += i - 1;
i = 1;
} else if (i < -1) {
ans += abs(i) - 1;
i = -1;
}
}
int negOne, zero, posOne;
negOne = zero = posOne = 0;
for (auto& i : v) {
negOne += (i == -1);
zero += (i == 0);
posOne += (i == 1);
}
if ((negOne & 1) && (zero)) {
zero--;
negOne++;
ans++;
}
if (negOne & 1) {
ans += 2;
}
cout << ans + zero << '\n';
return 0;
}