This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
using namespace std;
int n,v[5010],ans;
int main()
{
cin>>n;
for(int i=1;i<=n;++i)
cin>>v[i];
bool ok=false;
while(ok==false)
{
ok=true;
for(int i=1;i<n;++i)
{
if(v[i]>=v[i+1]+2)
{
ok=true;
++ans;
swap(v[i],v[i+1]);
}
}
for(int i=n;i>1;--i)
{
if(v[i-1]>=v[i]+2)
{
ok=true;
++ans;
swap(v[i],v[i-1]);
}
}
}
cout<<ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |