Skip to content

Instantly share code, notes, and snippets.

@Nimishkhurana
Created August 7, 2019 17:14
Show Gist options
  • Save Nimishkhurana/2e4e210d5b8294b4c116635d67699dd9 to your computer and use it in GitHub Desktop.
Save Nimishkhurana/2e4e210d5b8294b4c116635d67699dd9 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
int T,N;
cin>>T;
while(T--){
cin>>N;
int c[N],h[N],l,r;
for(int i=0;i<N;i++)
cin>>c[i];
for(int i=0;i<N;i++)
cin>>h[i];
int *final_poer = new int[N];
for(int i=0;i<N;i++){
l = max(1,(i+1)-c[i]);
r = min(N,(i+1)+c[i]);
final_poer[l-1]+=1;
if(r<N)
final_poer[r]-=1;
}
for (int i = 0; i < N; i++) {
if (i != 0)
final_poer[i] = final_poer[i] + final_poer[i - 1];
// std::cout << final_poer[i] << "\t";
}
sort(final_poer,final_poer+N);
sort(h,h+N);
int i;
for(i=0;i<N;i++){
if(final_poer[i]!=h[i]){
cout<<"NO"<<endl;
break;
}
}
if(i==N)
cout<<"YES"<<endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment