-
Notifications
You must be signed in to change notification settings - Fork 1
/
Tax_Calculator.cpp
63 lines (62 loc) · 1.18 KB
/
Tax_Calculator.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
60
61
62
63
#include <iostream>
#include <limits.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int *arr = new int[n];
int index = 0;
bool flag = true;
for (int i = 0; i < n; i++) {
cin >> arr[i];
if (flag && arr[i] != -1) {
index = i;
flag = false;
}
}
int element = arr[index];
bool flag2 = false;
bool flag3 = false;
bool impossible = false;
int mod_value = -1;
for (int i = index+1; i < n; i++) {
if (arr[i] != -1) {
if (flag2) {
if (arr[i] > mod_value) {
impossible = true;
break;
}
}
if (i - index != arr[i] - element) {
if (!flag2) {
int index1 = i - arr[i];
if (index1 < index ||(index1== index && element == 1)) {
impossible = true;
break;
}
mod_value = element + (index1 - index);
flag2 = true;
}
else {
if (((element + (i - index)) % mod_value) != arr[i]) {
impossible = true;
break;
}
}
}
element = arr[i];
index = i;
}
}
if (impossible)
cout << "impossible" << endl;
else if (mod_value == -1)
cout << "inf" << endl;
else
cout << mod_value << endl;
}
return 0;
}