-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBlackCells.cpp
57 lines (48 loc) · 865 Bytes
/
BlackCells.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
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int solve()
{
ll n;
cin>>n;
vector<ll> a(n);
for (int i = 0; i < n; i++)
{
cin>>a[i];
}
if(n%2==0){
ll ans =0;
for (ll i = 0; i < n; i+=2)
{
ans = max(ans,a[i+1]-a[i]);
}
cout<<max(ans,1LL)<<endl;
}
else{
ll ans =1e18;
for (ll i = 0; i < n; i+=2)
{
ll res =0;
for (ll j = 0; j < n;j+=2)
{
if(i==j){
j--;
continue;
}
res=max(res,a[j+1]-a[j]);
}
ans = min(ans,res);
}
cout<<max(ans,1LL)<<endl;
}
return 0;
}
int main()
{
int tc;
cin>>tc;
while(tc--)
{
solve();
}
}