forked from shivaylamba/Hacktoberfest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
25780367.java
63 lines (59 loc) · 1.51 KB
/
25780367.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for(int i=0;i<t;i++){
int n=sc.nextInt();
int c[]= new int[n];
int h[]=new int[n];
int r[]=new int[n];
int qs[]=new int[n];
int qe[]=new int[n];
int sum[]=new int [n];
for(int j=0;j<n;j++)
{ c[j]=sc.nextInt();
r[j]=0;}
for(int j=0;j<n;j++)
h[j]=sc.nextInt();
for(int j=0;j<n;j++){
qs[j]=j-c[j];
if(qs[j]<=0) qs[j]=0;
qe[j]=j+c[j];
if(qe[j]>=n-1) qe[j]=n-1;
}
for(int j=0;j<n;j++){
sum[qs[j]]++;
if(qe[j]+1<n) sum[qe[j]+1]--;
}
r[0]+=sum[0];
for (int ji = 1; ji < n; ji++)
{
sum[ji] += sum[ji - 1];
r[ji] += sum[ji];
}
int f=0,a=0;
Arrays.sort(h);
Arrays.sort(r);
//for(int k=0;k<n;k++)
//System.out.print(h[k]);
for(int k=0;k<n;k++){
// System.out.println(r[k]);
if(h[k]==r[k])f++;
//h[q]=-1;
//System.out.println("ghghj");
// break;}
}
//if(f==0) {System.out.print(r[k]+"-"+k);
//a=1; break;}
if(f!=n) System.out.println("NO");
else System.out.println("YES");
}
}
}