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 "bits/stdc++.h"
using namespace std;
// Hi ☻
int n,m; // towerscnt, mxjump
vector<int> h;
int main(){
ios::sync_with_stdio(0);cin.tie(0);
cin>>n>>m;
h.assign(n+1,0);
for(int i = 1;i<=n;i++)cin>>h[i];
vector<int> reach(n+1,0); // reach[i] max height possible to get to this
vector<int> ans(n+1,0);
for(int i=0;i<n;i++){
// get max height possible up to i+1, with least changes possible
ans[i+1] = ans[i];
if(reach[i]+m >= h[i+1]){
// don't change anything
reach[i+1] = h[i+1];
}else{
reach[i+1] = reach[i]+m;
ans[i+1] ++;
}
// cout<<reach[i+1]<<" ";
}
// cout<<endl;
cout<< ans[n] << '\n';
return 0;
}
/*
5 400
300
700
200
1000
500
3 300
700
1000
1300
*/
# | 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... |