initial commit

This commit is contained in:
ShazidMahsrafi 2023-07-25 17:31:17 +06:00
parent c24ac8c407
commit 1d75ddba8d

54
1853A Desorting/1853A.cpp Normal file
View File

@ -0,0 +1,54 @@
#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();
}