Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.lang.*;
- import java.io.*;
- public class Main
- {
- public static void main (String[] args) throws java.lang.Exception
- {
- Scanner sc = new Scanner(System.in);
- int n = sc.nextInt();
- int x = sc.nextInt();
- int[] arr = new int[n];
- int st = -1;
- int ed = -1;
- for(int i = 0 ; i < n ; i++){
- arr[i] = sc.nextInt();
- if(i-x >= 0 || i+x <= n-1) continue;
- if(st == -1) st = i;
- ed = i;
- }
- // st = 1 ed = 2
- // checking if non swap area is sorted or not
- st=Math.max(0,st);
- ed=Math.min(ed,n-1);
- for(int i = st ; i < ed -1 ; i++){
- if(arr[i] > arr[i+1]){
- System.out.println("NO"); // non swapping sorted or not
- return ;
- }
- }
- // non swap area either does not exist or it is sorted.
- System.out.println("YES");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement