Codeforces-SolutionsA/1853A Desorting/1853A.cpp
2023-07-25 17:31:17 +06:00

54 lines
819 B
C++

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
void solve()
{
int n;
cin>>n;
vector<int>v;
for(int i=0; i<n; ++i)
{
int x;
cin>>x;
v.push_back(x);
}
bool unsorted=0;
for(int i=1; i<n; ++i)
{
if(v[i]<v[i-1])
{
unsorted=1;
break;
}
}
if(unsorted)
cout<<0<<endl;
else
{
int d=INT_MAX;
for(int i=1; i<n; ++i)
{
int r;
r=v[i]-v[i-1];
if(r<d)
{
d=r;
}
}
int ans=(d/2)+1;
cout<<ans<<endl;
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int TC = 1;
cin >> TC;
cin.ignore();
while (TC--) solve();
}