Can someone explain why this code in JAVA gives WA?
import java.io.;
import java.util.;
class Permshuff
{
public static void main(String [] args)
{
InputReader1 reader = new InputReader1(System.in);
PrintWriter out=new PrintWriter(System.out);
int t=reader.nextInt();
while(t–>0)
{
int n=reader.nextInt();
int m=reader.nextInt();
boolean flag=true;
Integer a[]=new Integer[n];
for(int i=0;i<n;i++)
a[i]=reader.nextInt();
while(m–>0)
{
int from=reader.nextInt();
int to=reader.nextInt();
Arrays.sort(a,from-1,to);
}
for(int i=0;i<n;i++)
{
if(a[i]!=i+1)
{
flag=false;
break;
}
}
if(flag)
out.println(“Possible”);
else
out.println(“Impossible”);
out.flush();
}
out.close();
}
}
class InputReader1
{
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
public InputReader1(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public int nextInt() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c & 15;
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public long nextLong() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c & 15;
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public String next() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public String nextLine() {
int c = read();
//while (c != '\n' && c != '\r' && c != '\t' && c != -1)
//c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (c != '\n' && c != '\r' && c != '\t' && c != -1);
return res.toString();
}
public static boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
}