Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- int x=in.nextInt();
- for (int t = 0; t <x ; t++) {
- int d=in.nextInt();
- int[] num=new int[d];
- int[] cool=new int[d];
- int[] jerox=new int[d];
- for (int i = 0; i <d ; i++) {
- num[i]=in.nextInt();
- cool[i]=num[i];
- jerox[i]=num[i];
- }
- Arrays.sort(cool);
- boolean b=false;
- for (int i = 0; i <(num.length)-1 ; i++) {
- for (int j = 0; j <d ; j++) {
- num[j]=jerox[j];
- }
- int[] temp=new int[num.length];
- int k=-1;
- for (int j = 0; j <=i ; j++) {
- k++;
- temp[k]=num[j];
- num[j]=0;
- }
- int count=0;
- for(int a:temp){
- if(a!=0){
- count++;
- }
- }
- k=-1;
- for (int j = 0; j <num.length; j++) {
- if(j<(num.length)-count){
- num[j]=num[j+count];
- }else {
- k++;
- num[j]=temp[k];
- }
- }
- Arrays.fill(temp,0);
- if(Arrays.equals(cool,num)){
- b=true;
- break;
- }
- // for(int s:num){
- // System.out.print(s+" ");
- // }
- // System.out.println();
- }
- if(b==true){
- System.out.println("YES");
- }else{
- System.out.println("NO");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement