Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- int main(){
- int n, k;
- cin>>n>>k;
- vector<int> p(n);
- for(int i=0;i<n;i++){
- cin>>p[i];
- }
- int m1=0, m2=0;
- int ans=0;
- bool fl=false;
- while(1){
- m2++;
- if(m2==n){
- ans++;
- break;
- }
- if(p[m2]-p[m1]>k){
- if(!fl){
- cout<<-1;
- return 0;
- }
- ans++;
- m1=m2-1;
- m2=m2-1;
- fl=false;
- }
- else{
- fl=true;
- }
- }
- cout<<ans;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement