-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCOVID19.cpp
64 lines (61 loc) · 1.06 KB
/
COVID19.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
64
/*
https://www.codechef.com/MAY20B/problems/COVID19
*/
#include<bits/stdc++.h>
using namespace std;
int left_trav(int *pos, int i, int n)
{
if (i == 0) return 0;
int infected = 0;
for(int j = i-1; -1 < j; j--)
{
int dist_diff = abs(pos[j]-pos[j+1]);
if(dist_diff <= 2)
{
infected++;
}
else break;
}
return infected;
}
int right_trav(int *pos, int i, int n)
{
if(i == n-1) return 0;
int infected = 0;
for(int j = i+1; j < n; j++)
{
int dist_diff = abs(pos[j-1]-pos[j]);
if(dist_diff <= 2)
{
infected++;
}
else break;
}
return infected;
}
int main()
{
int test_cases;
cin >> test_cases;
while(test_cases--)
{
int n;
cin >> n;
int min_inf = INT_MAX, max_inf = INT_MIN;
int *pos = NULL;
pos = new int [n];
for(int i = 0; i < n; i++)
{
cin >> pos[i];
}
for(int i = 0; i < n; i++)
{
int infected = 1;
infected += left_trav(pos,i,n) + right_trav(pos,i,n);
if (infected < min_inf) min_inf = infected;
if (max_inf < infected) max_inf = infected;
}
cout << min_inf << " " << max_inf << endl;
}
return 0;
}