#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
int work1(vector<int> a,int n,int m){
int ans=0;
for(int i=0;i<n-1;i++){
if(a[i+1]-a[i]<=m){
continue;
}else{
a[i+1]=a[i]+m;
ans++;
}
}
return ans;
}
int work2(vector<int> a,int n,int m){
int ans=0;
for(int i=n-2;i>=0;i--){
if(a[i+1]-a[i]<=m){
continue;
}else{
a[i]=a[i+1]-m;
ans++;
}
}
return ans;
}
int work3(vector<int> a,int n,int m){
a[0]=a[1]-m;
return work1(a,n,m);
}
int work4(vector<int> a,int n,int m){
a[n-1]=a[n-2]+m;
return work2(a,n,m);
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int n,m;
cin>>n>>m;
vector<int> a(n);
for(int i=0;i<n;i++){
cin>>a[i];
}
if(n==1){
cout<<(a[0]>m)<<endl;
return 0;
}
int ans1=work1(a,n,m),ans2=work2(a,n,m),ans3=work3(a,n,m),ans4=work4(a,n,m);
ans1=min(ans1,ans2);
ans1=min(ans1,ans3);
ans1=min(ans1,ans4);
cout<<ans1<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Incorrect |
1 ms |
508 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Incorrect |
1 ms |
508 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Incorrect |
1 ms |
508 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Incorrect |
1 ms |
508 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |