Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.

There are $N$ caves in a row, numbered $1$ through $N$. For each valid $i$, the *radiation power* in the $i$-th cave is $C_{i}$. Originally, the *radiation level* in each cave was $0$. Then, for each valid $i$, the radiation power in cave $i$ increased the radiation levels in the caves $i-C_{i}, \ldots, i+C_{i}$ inclusive (if they exist) by $1$, so all the caves are radioactive now.

Radiation is not the only problem, though. There are also $N$ zombies with health levels $H_{1}, H_{2}, \ldots, H_{N}$. You want to kill all of them by getting them to the caves in such a way that there is exactly one zombie in each cave. A zombie dies in a cave if and only if the radiation level in that cave is equal to the health level of the zombie. Is it possible to kill all the zombies?

------  Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains $N$ space-separated integers $C_{1}, C_{2}, \ldots, C_{N}$.
The third line contains $N$ space-separated integers $H_{1}, H_{2}, \ldots, H_{N}$.

------  Output ------
For each test case, print a single line containing the string "YES" if it is possible to kill all the zombies or "NO" if it is impossible (without quotes).

------  Constraints  ------
$1 ≤ T ≤ 100$
$1 ≤ N ≤ 10^{5}$
$1 ≤ C_{i}, H_{i} ≤ 10^{9}$ for each valid $i$

------  Subtasks ------
Subtask #1 (30 points): $1 ≤ N ≤ 1,000$

Subtask #2 (70 points): original constraints

----- Sample Input 1 ------ 
2

5

1 2 3 4 5

1 2 3 4 5

5

1 2 3 4 5

5 4 3 4 5
----- Sample Output 1 ------ 
NO

YES
----- explanation 1 ------ 
In both example test cases, the final radiation levels in the caves are $(5, 5, 4, 4, 3)$. For example, the radiation power in cave $1$ increased the radiation levels in caves $1$ and $2$ (there is no cave $0$) by $1$, and the radiation power in cave $4$ increased the radiation levels in all caves by $1$.

Difficulty: MEDIUM_HARD
Tags: Sorting

Data structures

Range queries
Skill types: Sorting

Data structures

Range queries

Starter code:

Solutions:
for _ in range(int(input())):
	n = int(input())
	rads = list(map(int, input().split()))
	health = list(map(int, input().split()))
	mem = max(max(rads), n)
	temp = [0 for i in range(n + 2)]
	for i in range(1, n + 1):
		ma = max(0, i - rads[i - 1])
		mi = min(n + 1, i + rads[i - 1] + 1)
		temp[ma] += 1
		temp[mi] -= 1
	cnt = 0
	for i in range(len(temp)):
		temp[i] += cnt
		cnt = temp[i]
	cuts = temp[1:n + 1]
	cuts.sort()
	health.sort()
	if cuts == health:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	power = list(map(int, input().split()))
	zombie = list(map(int, input().split()))
	m = max(max(power), n)
	temp = [0 for i in range(n + 2)]
	for i in range(1, n + 1):
		mi = max(0, i - power[i - 1])
		ma = min(n + 1, i + power[i - 1] + 1)
		temp[mi] += 1
		temp[ma] -= 1
	s = 0
	for i in range(len(temp)):
		temp[i] += s
		s = temp[i]
	cutout = temp[1:1 + n]
	cutout.sort()
	zombie.sort()
	if cutout == zombie:
		print('YES')
	else:
		print('NO')


from bisect import bisect_left
from heapq import heapify, heappush, heappop
from collections import deque
import sys
from math import gcd, sqrt, log10, log2, floor, ceil, sqrt
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)

def il():
	return [int(a) for a in input().strip().split()]

def ip():
	return input().strip()

def ii():
	return int(input())

def ot(in_p, *args, e=' '):
	if type(in_p) == list:
		print(*in_p, end=e)
	if type(in_p) == str or type(in_p) == int:
		print(in_p, end=e)
		for l in args:
			print(l, end=e)
	print()

def a_pwr_n(a, n, mod):
	if n == 1:
		return a % mod
	if n % 2 == 0:
		val = a_pwr_n(a, n // 2, mod)
		return val % mod * val % mod
	else:
		return a % mod * a_pwr_n(a, n - 1, mod) % mod

def rg(*ag):
	if len(ag) == 3:
		return range(ag[0], ag[1], ag[2])
	elif len(ag) == 2:
		return range(ag[0], ag[1])
	elif len(ag) == 1:
		return range(ag[0])
	else:
		raise 'invalid input'

def ispal(i, j, st):
	while i <= j:
		if st[i] == st[j]:
			i = i + 1
			j = j - 1
		else:
			return False
	return True
mod = 1000000000 + 7
dx = [-1, -2, 1, 2, 2, -2, -1, 1]
dy = [2, 1, 2, 1, -1, -1, -2, -2]
for _ in range(ii()):
	n = ii()
	c = il()
	zombie = il()
	ans = []
	for i in range(n + 1):
		ans.append(0)
	for k in range(n):
		low = max(1, k + 1 - c[k])
		hi = min(n, k + 1 + c[k])
		ans[low - 1] -= 1
		ans[hi] += 1
	for l in range(n - 1, 0, -1):
		ans[l] += ans[l + 1]
	ans1 = sorted(ans[1:])
	ans2 = sorted(zombie)
	if ans1 == ans2:
		print('YES')
	else:
		print('NO')


T = int(input())
for _ in range(T):
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	Diff = [0] * (n + 1)
	A.insert(0, 0)
	for i in range(1, n + 1):
		if i - A[i] < 1:
			Diff[1] += 1
		else:
			Diff[i - A[i]] += 1
		if i + A[i] + 1 <= n:
			Diff[i + A[i] + 1] -= 1
	for i in range(2, n + 1):
		Diff[i] += Diff[i - 1]
	Diff.pop(0)
	Diff.sort()
	B.sort()
	if Diff == B:
		print('YES')
	else:
		print('NO')


T = int(input())
for _ in range(T):
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	Diff = [0] * (n + 1)
	A.insert(0, 0)
	for i in range(1, n + 1):
		if i - A[i] < 1:
			Diff[1] += 1
		else:
			Diff[i - A[i]] += 1
		if i + A[i] + 1 <= n:
			Diff[i + A[i] + 1] -= 1
	for i in range(2, n + 1):
		Diff[i] += Diff[i - 1]
	Diff.pop(0)
	count = {}
	for i in range(n):
		if Diff[i] in count:
			count[Diff[i]] += 1
		else:
			count[Diff[i]] = 1
	flag = True
	for i in range(n):
		if B[i] not in count or count[B[i]] == 0:
			flag = False
			break
		else:
			count[B[i]] -= 1
	if flag == True:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	a = [0] * n
	for j in range(n):
		l = max(0, j - l1[j])
		r = j + l1[j] + 1
		a[l] += 1
		if r < n:
			a[r] -= 1
	for k in range(1, n):
		a[k] += a[k - 1]
	l2.sort()
	a.sort()
	print('YES' if a == l2 else 'NO')


for cases in range(int(input())):
	siz = int(input())
	rp = list(map(int, input().split()))
	hlth = list(map(int, input().split()))
	res = [0] * siz
	for i in range(siz):
		left = max(0, i - rp[i])
		right = i + 1 + rp[i]
		res[left] += 1
		if right < siz:
			res[right] -= 1
	for i in range(1, siz):
		res[i] += res[i - 1]
	res.sort()
	hlth.sort()
	if res == hlth:
		print('YES')
	else:
		print('NO')


n = int(input())
for i in range(n):
	k = int(input())
	rp = list(map(int, input().split()))
	hp = list(map(int, input().split()))
	radlev = [0] * k
	j = 0
	for i in range(k):
		j = i - rp[i]
		l = max(0, j)
		r = i + 1 + rp[i]
		radlev[l] += 1
		if r < k:
			radlev[r] -= 1
	for i in range(1, k):
		radlev[i] += radlev[i - 1]
	radlev.sort()
	hp.sort()
	if radlev == hp:
		print('YES')
	else:
		print('NO')


t = int(input())
while t:
	t -= 1
	x = int(input())
	pwr = list(map(int, input().split()))
	hlth = list(map(int, input().split()))
	hsum = sum(hlth)
	nsum = 0
	for i in range(x):
		l = i - pwr[i]
		if l <= 0:
			l = 0
		r = i + pwr[i]
		if r >= x:
			r = x - 1
		nsum += r - l + 1
	if nsum == hsum:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	caves = int(input())
	r_power = list(map(int, input().split()))
	health = list(map(int, input().split()))
	health_sum = sum(health)
	level_sum = 0
	for i in range(caves):
		left_level = i - r_power[i]
		right_level = i + r_power[i]
		if left_level <= 0:
			left_level = 0
		if right_level >= caves:
			right_level = caves - 1
		level_sum += right_level - left_level + 1
	if health_sum == level_sum:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	c = list(map(int, input().split()))
	h = list(map(int, input().split()))
	sumh = sum(h)
	newsum = 0
	for i in range(n):
		l = i - c[i]
		r = i + c[i]
		if l <= 0:
			l = 0
		if r >= n:
			r = n - 1
		newsum += r - l + 1
	if sumh == newsum:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	res = [0] * n
	for i in range(n):
		left = max(0, i - l1[i])
		right = i + 1 + l1[i]
		res[left] += 1
		if right < n:
			res[right] -= 1
	for i in range(1, n):
		res[i] += res[i - 1]
	res.sort()
	l2.sort()
	if res == l2:
		print('YES')
	else:
		print('NO')


test = int(input())
results = []
while test:
	n = int(input())
	ca = list(map(int, input().split()))
	zh = list(map(int, input().split()))
	d = [0] * n
	ra = [0] * n
	for i in range(n):
		if i - ca[i] < 0:
			d[0] += 1
		else:
			d[i - ca[i]] += 1
		if i + ca[i] + 1 < n:
			d[i + ca[i] + 1] -= 1
	for i in range(1, n):
		d[i] += d[i - 1]
	d.sort()
	zh.sort()
	flag = True
	for i in range(n):
		if zh[i] != d[i]:
			flag = False
			break
	if flag == False:
		results.append('NO')
	else:
		results.append('YES')
	test -= 1
for result in results:
	print(result)


def main():
	tests = int(input())
	for t in range(tests):
		n = int(input())
		C = list(map(int, input().split()))
		H = list(map(int, input().split()))
		x = [0] * n
		for i in range(n):
			l = max(0, i - C[i])
			r = i + C[i] + 1
			x[l] += 1
			if r < n:
				x[r] -= 1
		for i in range(1, n):
			x[i] += x[i - 1]
		H.sort()
		x.sort()
		if x == H:
			print('YES')
		else:
			print('NO')
main()


for _ in range(int(input())):
	n = int(input())
	c = list(map(int, input().split()))
	h = list(map(int, input().split()))
	l = [0] * (n + 1)
	for i in range(1, n + 1):
		(st, en) = (i - c[i - 1], i + c[i - 1])
		if st <= 1:
			l[1] += 1
		else:
			l[st] += 1
		if en + 1 <= n:
			l[en + 1] -= 1
	for i in range(1, n + 1):
		l[i] += l[i - 1]
	l.pop(0)
	l.sort()
	h.sort()
	print(['NO', 'YES'][l == h])


for _ in range(int(input())):
	n = int(input())
	rp = [0] * (n + 1)
	c = list(map(int, input().split()))
	h = list(map(int, input().split()))
	for i in range(n):
		rp[0 if i - c[i] < 0 else i - c[i]] += 1
		rp[n if i + c[i] >= n else i + c[i] + 1] -= 1
	c[0] = rp[0]
	for i in range(1, n):
		c[i] = rp[i] + c[i - 1]
	c.sort()
	h.sort()
	for i in range(n):
		if c[i] != h[i]:
			print('NO')
			break
	else:
		print('YES')


T = int(input())
for i in range(T):
	n = int(input())
	c = [int(x) for x in input().split()]
	h = [int(x) for x in input().split()]
	d = [0] * (n + 1)
	for i in range(n):
		if i - c[i] < 0:
			d[0] += 1
		else:
			d[i - c[i]] += 1
		if i + c[i] >= n:
			d[n] -= 1
		else:
			d[i + c[i] + 1] -= 1
	c[0] = d[0]
	for i in range(1, n):
		c[i] = d[i] + c[i - 1]
	c = sorted(c)
	h = sorted(h)
	if c == h:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	c = list(map(int, input().split()))
	h = list(map(int, input().split()))
	sum1 = 0
	for i in range(n):
		a = max(0, i - c[i])
		b = min(n - 1, i + c[i])
		sum1 = sum1 + b - a + 1
	if sum1 == sum(h):
		print('YES')
	else:
		print('NO')


t = int(input())
for test in range(t):
	n = int(input())
	c = list(map(int, input().split()))
	h = sorted(list(map(int, input().split())))
	ranges = [0] * (n + 1)
	for i in range(n):
		ci = c[i]
		if i - ci <= 0:
			ranges[0] += 1
		else:
			ranges[i - ci] += 1
		if i + ci >= n:
			ranges[n] -= 1
		else:
			ranges[i + ci + 1] -= 1
	c[0] = ranges[0]
	for j in range(1, n):
		c[j] = ranges[j] + c[j - 1]
	c.sort()
	if c == h:
		print('YES')
	else:
		print('NO')


T = int(input())
ans = []
for _ in range(T):
	N = int(input())
	C = [int(i) for i in input().split()]
	H = [int(i) for i in input().split()]
	F = [0 for i in range(N + 1)]
	for i in range(N):
		l = max(0, i - C[i])
		r = min(N - 1, i + C[i]) + 1
		F[l] += 1
		F[r] -= 1
	s = 0
	D = {}
	for i in range(N):
		s += F[i]
		D[s] = True
	for i in range(N):
		if H[i] not in D:
			ans.append('NO')
			break
	else:
		ans.append('YES')
for i in ans:
	print(i)


t = int(input(''))
for _ in range(t):
	n = int(input(''))
	c = list(map(int, input('').strip().split()))[:n]
	h = list(map(int, input('').strip().split()))[:n]
	l = [0] * n
	for i in range(n):
		if i - c[i] >= 0:
			l[i - c[i]] += 1
		else:
			l[0] += 1
		if i + c[i] + 1 < n:
			l[i + c[i] + 1] -= 1
	for i in range(1, n):
		l[i] += l[i - 1]
	l.sort()
	h.sort()
	if l == h:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	count = [0 for i in range(n)]
	for i in range(n):
		le = max(i - a[i], 0)
		ri = min(i + a[i], n - 1)
		count[le] += 1
		if ri + 1 < n:
			count[ri + 1] -= 1
	for i in range(1, n):
		count[i] = count[i] + count[i - 1]
	count.sort()
	b.sort()
	if count == b:
		print('YES')
	else:
		print('NO')


T = int(input())
for i in range(T):
	N = int(input())
	C = list(map(int, input().split()))
	H = list(map(int, input().split()))
	Ar = [0] * N
	for i in range(N):
		min = i - C[i]
		if min < 0:
			min = 0
		Ar[min] += 1
		max = i + C[i] + 1
		if max <= N - 1:
			Ar[max] -= 1
	for i in range(1, N):
		Ar[i] = Ar[i - 1] + Ar[i]
	Ar.sort()
	H.sort()
	if Ar == H:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	c1 = list(map(int, input().split()))
	h = list(map(int, input().split()))
	c2 = [0 for k in range(n)]
	for i in range(n):
		l = i - c1[i]
		r = i + c1[i]
		if l >= 0:
			c2[l] = c2[l] + 1
		if r + 1 < n:
			c2[r + 1] = c2[r + 1] - 1
		if l < 0:
			c2[0] += 1
	for x in range(1, n):
		c2[x] += c2[x - 1]
	c2.sort()
	h.sort()
	if c2 == h:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	c = list(map(int, input().split()))
	h = list(map(int, input().split()))
	l = [0] * n
	for i in range(n):
		a = i + 1 - c[i]
		b = i + 1 + c[i]
		if a < 1:
			a = 1
		elif a > n:
			a = n
		if b < 0:
			b = 1
		elif b >= n:
			b = n
		try:
			l[a - 1] += 1
			l[b] -= 1
		except:
			pass
	for i in range(1, n):
		l[i] = l[i] + l[i - 1]
	l.sort()
	h.sort()
	if l[:] == h[:]:
		print('YES')
	else:
		print('NO')


def main():
	n = int(input())
	c = list(map(int, input().split()))
	c = [0] + c
	h = list(map(int, input().split()))
	s = 0
	for i in range(1, n + 1):
		s = s + min(i + c[i] + 1, n + 1) - max(1, i - c[i])
	if s == sum(h):
		print('YES')
	else:
		print('NO')
for _ in range(int(input())):
	main()


t = int(input())
for k in range(t):
	n = int(input())
	c = list(map(int, input().split()))
	h = list(map(int, input().split()))
	a = [0] * n
	ans = 'YES'
	D = [0] * (n + 1)
	for i in range(n):
		l = i - c[i]
		r = i + c[i]
		if l >= 0:
			D[l] += 1
		else:
			D[0] += 1
		if r < n:
			D[r + 1] -= 1
		else:
			D[n] -= 1
	dict = {}
	a[0] = D[0]
	dict[a[0]] = 1
	for i in range(1, n):
		a[i] = a[i - 1] + D[i]
		if a[i] in dict:
			dict[a[i]] += 1
		else:
			dict[a[i]] = 1
	for i in h:
		if i in dict and dict[i] > 0:
			dict[i] -= 1
		else:
			ans = 'NO'
			break
	print(ans)


t = int(input())
while t:
	t -= 1
	n = int(input())
	power = list(map(int, input().split()))
	zombie = sorted(list(map(int, input().split())))
	active = [0] * (n + 1)
	for i in range(n):
		left = i - power[i]
		right = i + power[i]
		if left <= 0:
			left = 0
		if right >= n:
			right = n - 1
		active[left] = active[left] + 1
		active[right + 1] = active[right + 1] - 1
	for i in range(1, n):
		active[i] = active[i] + active[i - 1]
	active = active[:-1]
	active.sort()
	if active == zombie:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	sum1 = 0
	for j in range(n):
		a = max(0, j - l1[j])
		b = min(n - 1, j + l1[j])
		sum1 = sum1 + b - a + 1
	if sum1 == sum(l2):
		print('YES')
	else:
		print('NO')


for j in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))
	y = list(map(int, input().split()))
	s = 0
	for i in range(n):
		t1 = max(1, i + 1 - x[i])
		t2 = min(n, i + 1 + x[i])
		s += t2 - t1 + 1
	if s == sum(y):
		print('YES')
	else:
		print('NO')


T = int(input())
for i in range(T):
	N = int(input())
	c = list(map(int, input().split()))
	h = list(map(int, input().split()))
	s = 0
	for i in range(N):
		t1 = max(1, i + 1 - c[i])
		t2 = min(N, i + 1 + c[i])
		s += t2 - t1 + 1
	if s == sum(h):
		print('YES')
	else:
		print('NO')


import collections

def take_inputs():
	num_caves = int(input())
	C = list(map(int, input().split()))
	H = list(map(int, input().split()))
	if collections.Counter(H) == collections.Counter(compute_radiation_level(C, num_caves)):
		print('YES')
	else:
		print('NO')

def compute_radiation_level(C, num_caves):
	radiation_level = [0] * num_caves
	for i in range(num_caves):
		s = i + 1 - C[i]
		s = check_boundary(s, num_caves)
		e = i + 1 + C[i]
		e = check_boundary(e, num_caves)
		try:
			radiation_level[s - 1] += 1
			radiation_level[e] -= 1
		except:
			pass
	for i in range(1, num_caves):
		radiation_level[i] = radiation_level[i - 1] + radiation_level[i]
	return radiation_level

def check_boundary(number, num_caves):
	if number < 1:
		return 1
	elif number > num_caves:
		return num_caves
	else:
		return number
num_cases = int(input())
while num_cases != 0:
	num_cases -= 1
	take_inputs()


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	a = list(map(int, input().split()))
	diff = 0
	for i in range(n):
		left = max(1, i + 1 - l[i])
		right = min(n, i + 1 + l[i])
		diff += right - left + 1
	if diff == sum(a):
		print('YES')
	else:
		print('NO')


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	z = list(map(int, input().split()))
	s = 0
	for i in range(1, n + 1):
		tmp1 = i - a[i - 1]
		if tmp1 <= 0:
			tmp1 = 1
		tmp2 = i + a[i - 1]
		if tmp2 >= n:
			tmp2 = n
		s += tmp2 - tmp1 + 1
	if s == sum(z):
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	N = int(input())
	array = list(map(int, input().split()))
	zombies = list(map(int, input().split()))
	final = [0] * N
	for i in range(N):
		mn = i - array[i]
		mx = i + 1 + array[i]
		final[max(mn, 0)] += 1
		if mx <= N - 1:
			final[mx] -= 1
	sm = 0
	pakkaFinal = []
	for i in range(N):
		sm += final[i]
		pakkaFinal.append(sm)
	pakkaFinal.sort()
	zombies.sort()
	if zombies == pakkaFinal:
		print('YES')
	else:
		print('NO')


def destroy_zombie(radiation, zombie_health):
	for (x, y) in zip(radiation, zombie_health):
		if x != y:
			return False
	return True
t = int(input())
for _ in range(t):
	n = int(input())
	radiation_arr = list(map(int, input().strip().split()))
	zombies = list(map(int, input().strip().split()))
	cave_radiations = [0] * (len(radiation_arr) + 1)
	for (index, radiation) in enumerate(radiation_arr):
		caves = (max(0, index - radiation), min(index + radiation, len(radiation_arr) - 1))
		cave_radiations[caves[0]] += 1
		cave_radiations[caves[-1] + 1] -= 1
	for (index, radiation) in enumerate(cave_radiations):
		if index > 0:
			cave_radiations[index] += cave_radiations[index - 1]
	if destroy_zombie(sorted(cave_radiations[:len(zombies)]), sorted(zombies)):
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline
t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	diff = [0 for i in range(n)]
	for i in range(0, n):
		diff[max(0, i - a[i])] += 1
		if i + a[i] + 1 < n:
			diff[i + a[i] + 1] -= 1
	for i in range(1, n):
		diff[i] += diff[i - 1]
	if sorted(diff) == sorted(b):
		print('YES')
	else:
		print('NO')


from sys import stdin, stdout
import math
from itertools import permutations, combinations
from collections import defaultdict

def L():
	return list(map(int, stdin.readline().split()))

def Li():
	return map(int, stdin.readline().split())

def I():
	return int(stdin.readline())
P = 1000000007

def main():
	try:
		for _ in range(I()):
			n = I()
			l1 = L()
			l2 = sum(L())
			t = 0
			for i in range(len(l1)):
				t1 = i + 1 - l1[i]
				t2 = i + 1 + l1[i]
				if t1 <= 0:
					t1 = 1
				if t2 > len(l1):
					t2 = len(l1)
				t += t2 - t1 + 1
			if l2 != t:
				print('NO')
			else:
				print('YES')
	except:
		pass
main()


import numpy as np
from collections import Counter
for _ in range(int(input())):
	n = int(input())
	C = list(map(int, input().split()))
	H = list(map(int, input().split()))
	Hc = Counter(H)
	suma = [0 for _ in range(n)]
	fR = suma[:]
	for i in range(n):
		rl = C[i]
		up = i + rl if i + rl <= n - 1 else n - 1
		lo = i - rl if i - rl >= 0 else 0
		suma[lo] += 1
		if up + 1 < n:
			suma[up + 1] -= 1
	fR[0] += suma[0]
	for i in range(1, n):
		suma[i] += suma[i - 1]
		fR[i] += suma[i]
	ans = 'YES' if Counter(fR) == Hc else 'NO'
	print(ans)


for _ in range(int(input())):
	n = int(input())
	radiation = list(map(int, input().split()))
	health = list(map(int, input().split()))
	array = [0] * (n + 2)
	for i in range(n):
		if i + 1 - radiation[i] < 1:
			array[1] += 1
		else:
			array[i + 1 - radiation[i]] += 1
		if i + 1 + radiation[i] > n:
			array[-1] -= 1
		else:
			array[i + 2 + radiation[i]] -= 1
	this = []
	for i in range(n):
		this.append(array[i] + array[i + 1])
		array[i + 1] += array[i]
	if sorted(this) == sorted(health):
		print('YES')
	else:
		print('NO')


radiation = []

def rangeUpdate(i, Ci, lim):
	(l, r) = (max(i - Ci, 0), min(lim, i + Ci))
	radiation[l] += 1
	if r < lim:
		radiation[r + 1] += -1
T = int(input().strip())
for _ in range(T):
	N = int(input().strip())
	C = [int(x) for x in input().strip().split(' ')]
	H = [int(x) for x in input().strip().split(' ')]
	radiation = [0] * N
	[rangeUpdate(i, j, N - 1) for (i, j) in enumerate(C)]
	(ans, rs) = (0, 0)
	for (i, j) in zip(radiation, H):
		rs += i
		ans ^= rs ^ j
	if ans == 0:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	c = [int(x) for x in input().split()]
	h = [int(x) for x in input().split()]
	rad = [0 for x in range(n)]
	farr = [0 for x in range(n)]
	farrsum = [0 for x in range(n)]
	for i in range(n):
		ci = c[i]
		start = i - ci
		end = i + ci
		summ = 0
		if start > 0 and end < n:
			farr[end] += 1
			farr[start - 1] -= 1
		elif start <= 0 and end >= n:
			farr[n - 1] += 1
		elif start > 0 and end >= n:
			farr[n - 1] += 1
			farr[start - 1] -= 1
		else:
			farr[end] += 1
	for k in reversed(range(n)):
		summ += farr[k]
		farrsum[k] = summ
	farrsum = sorted(farrsum)
	h = sorted(h)
	flag = 0
	for i in range(n):
		if farrsum[i] != h[i]:
			flag = 1
			break
	if flag == 0:
		print('YES')
	else:
		print('NO')


from collections import Counter

def compare(s, t):
	return Counter(s) == Counter(t)
n = int(input())
for _ in range(n):
	m = int(input())
	input1 = list(map(int, input().split()))
	input2 = list(map(int, input().split()))
	sorted(input2, reverse=True)
	l = []
	for i in range(m):
		l.append(0)
	for i in range(m):
		start = i - input1[i]
		end = i + input1[i] + 1
		if start < 0:
			start = 0
		if end > m:
			end = m
		l[start] = l[start] + 1
		if end < m:
			l[end] = l[end] - 1
	for i in range(1, len(l)):
		l[i] = l[i] + l[i - 1]
	if compare(l, input2):
		print('YES')
	else:
		print('NO')


def solve(N, C, Z):
	ar = [0 for _ in range(N)]
	ar2 = ar.copy()
	r = 0
	for i in range(len(C)):
		if i + C[i] + 1 < N:
			ar[i + C[i] + 1] -= 1
	for i in range(N):
		ar[i] += r + 1
		r = ar[i]
	r = 0
	for i in range(len(C)):
		if i - C[i] - 1 >= 0:
			ar2[i - C[i] - 1] -= 1
	for i in range(N)[::-1]:
		ar2[i] += r + 1
		r = ar2[i]
	for i in range(N):
		ar[i] += ar2[i] - 1
	ar.sort()
	Z.sort()
	return ar == Z

def main():
	for _ in range(int(input())):
		N = int(input())
		C = list(map(int, input().split()))
		Z = list(map(int, input().split()))
		if solve(N, C, Z):
			print('YES')
		else:
			print('NO')
main()


test_inputs = int(input())
for test in range(test_inputs):
	n = int(input())
	radiation = list(map(int, input().split()))
	health = list(map(int, input().split()))
	cur_radiations = [0 for _ in range(n + 1)]
	for i in range(n):
		(l, r) = (max(0, i - radiation[i]), min(n - 1, i + radiation[i]))
		cur_radiations[l] += 1
		cur_radiations[r + 1] -= 1
	for i in range(1, n):
		cur_radiations[i] = cur_radiations[i - 1] + cur_radiations[i]
	cur_radiations = cur_radiations[0:-1]
	flag = 0
	(count_health, count_radiation) = ({}, {})
	for r in cur_radiations:
		if r not in count_radiation:
			count_radiation[r] = 1
		else:
			count_radiation[r] += 1
	for h in health:
		if h not in count_health:
			count_health[h] = 1
		else:
			count_health[h] += 1
	for key in count_health.keys():
		if key not in count_radiation:
			flag = 1
			break
		elif count_radiation[key] != count_health[key]:
			flag = 1
			break
	if flag == 1:
		print('NO')
	else:
		print('YES')


def main():
	n_tests = int(input())
	for i in range(n_tests):
		print(handle_test())

def handle_test():
	input()
	powers = list(map(int, input().split()))
	p_diffs = difference_array(powers)
	levels = sorted(diffs_to_levels(p_diffs))
	healths = sorted(list(map(int, input().split())))
	if levels == healths:
		return 'YES'
	return 'NO'

def difference_array(xs):
	diffs = [0] * len(xs)
	for (i, x) in enumerate(xs):
		left = max(0, i - x)
		right = i + x + 1
		diffs[left] += 1
		if right < len(xs):
			diffs[right] -= 1
	return diffs

def diffs_to_levels(xs):
	level = 0
	levels = []
	for x in xs:
		level += x
		levels.append(level)
	return levels
main()


for _ in range(int(input())):
	n = int(input())
	c = [int(x) for x in input().split()]
	h = [int(x) for x in input().split()]
	r = [0 for i in range(n)]
	for i in range(n):
		start = i - c[i]
		end = i + c[i]
		if start < 0:
			start = 0
		if end > n:
			end = n - 1
		r[start] += 1
		if end < n - 1:
			r[end + 1] -= 1
	for i in range(1, n):
		r[i] += r[i - 1]
	r.sort()
	h.sort()
	if r == h:
		print('YES')
	else:
		print('NO')


t = int(input())
while t > 0:
	n = int(input())
	c = list(map(int, input().split()))
	h = list(map(int, input().split()))
	arr = [0 for i in range(n)]
	for i in range(n):
		x = i - c[i]
		y = i + c[i]
		if x >= 0:
			arr[x] = arr[x] + 1
		if y + 1 < n:
			arr[y + 1] = arr[y + 1] - 1
		if x < 0:
			arr[0] += 1
	for j in range(1, n):
		arr[j] = arr[j] + arr[j - 1]
	arr.sort()
	h.sort()
	if arr == h:
		print('YES')
	else:
		print('NO')
	t -= 1


def ZomRad(arr):
	for i in range(1, len(arr)):
		arr[i] = arr[i] + arr[i - 1]
	arr.pop()
	del arr[0]
	return arr
for _t in range(int(input())):
	n = int(input())
	c = list(map(int, input().split()))
	h = list(map(int, input().split()))
	rLevel = [0] * (n + 2)
	lm = len(rLevel)
	for i in range(0, n):
		rLevel[max(1, i + 1 - c[i])] += 1
		rLevel[min(i + 1 + c[i] + 1, n + 1)] -= 1
	rLevel = ZomRad(rLevel)
	if sorted(h) == sorted(rLevel):
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	c = list(map(int, input().split()))
	h = list(map(int, input().split()))
	p = [0] * (n + 1)
	for i in range(1, n + 1):
		x = max(1, i - c[i - 1])
		y = i + 1 + c[i - 1]
		p[x] += 1
		if y <= n:
			p[y] -= 1
	for i in range(1, n + 1):
		p[i] += p[i - 1]
	if sorted(p[1:n + 1]) == sorted(h):
		print('YES')
	else:
		print('NO')


T = int(input())
for t in range(T):
	N = int(input())
	C = list(map(int, input().split(' ')))
	H = list(map(int, input().split(' ')))
	A = [0] * N
	for i in range(N):
		l = i - C[i]
		h = i + C[i]
		if l < 0:
			l = 0
		A[l] += 1
		if h < N - 1:
			A[h + 1] -= 1
	for i in range(1, N):
		A[i] += A[i - 1]
	if sorted(H) == sorted(A):
		print('YES')
	else:
		print('NO')


t = int(input())
while t:
	t = t - 1
	n = int(input())
	c = list(map(int, input().split()))
	h = list(map(int, input().split()))
	rad = [0] * (n + 1)
	for i in range(n):
		l = i - c[i]
		r = i + c[i]
		if l <= 0:
			l = 0
		if r >= n:
			r = n - 1
		rad[l] = rad[l] + 1
		rad[r + 1] = rad[r + 1] - 1
	for i in range(n - 1):
		rad[i + 1] = rad[i] + rad[i + 1]
	rad.remove(rad[n])
	rad.sort()
	h.sort()
	if rad == h:
		print('YES')
	else:
		print('NO')


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	radpow = list(map(int, input().split(' ')))
	zombie = list(map(int, input().split(' ')))
	temp = 0
	for i in range(len(radpow)):
		first = i + 1 - radpow[i]
		last = i + 1 + radpow[i]
		if first <= 0:
			first = 1
		if last > len(radpow):
			last = len(radpow)
		temp += last - first + 1
	if sum(zombie) != temp:
		print('NO')
		continue
	print('YES')


t = int(input(''))
C = []
while t > 0:
	n = int(input(''))
	c_i = [int(i) for i in input('').split(' ')]
	h_i = [int(i) for i in input('').split(' ')]
	C = [0 for i in range(n)]
	for i in range(n):
		L = i - c_i[i]
		R = i + c_i[i]
		if L >= 0:
			C[L] += 1
		if L < 0:
			C[0] += 1
		if R < n - 1:
			C[R + 1] -= 1
	for i in range(1, n):
		C[i] += C[i - 1]
	h_i.sort(reverse=True)
	C.sort(reverse=True)
	if h_i == C:
		print('YES')
	else:
		print('NO')
	t -= 1


def f():
	t = int(input())
	while t > 0:
		n = int(input())
		rad = list(map(int, input().split()))
		hel = list(map(int, input().split()))
		l = []
		val = 0
		a = [0] * n
		for i in range(n):
			x = i - rad[i]
			x1 = i + rad[i]
			if x < 0:
				x = 0
			if x1 > n - 1:
				x1 = n - 1
			val += x1 - x + 1
		sum1 = sum(hel)
		if sum1 == val:
			print('YES')
		else:
			print('NO')
		t -= 1
f()


t = int(input())
for _ in range(t):
	n = int(input())
	c = list(map(int, input().strip().split()))
	h = list(map(int, input().strip().split()))
	diff = [0 for i in range(n + 1)]
	power = [0 for i in range(n)]
	for i in range(n):
		diff[max(0, i - c[i])] += 1
		diff[min(n, i + c[i] + 1)] -= 1
	power[0] = diff[0]
	for i in range(1, n):
		power[i] = power[i - 1] + diff[i]
	power.sort()
	h.sort()
	flag = True
	for i in range(n):
		if power[i] != h[i]:
			flag = False
			break
	if flag:
		print('YES')
	else:
		print('NO')


import collections
T = int(input())
for _ in range(T):
	flag = 0
	N = int(input())
	powers = {key: val for (key, val) in enumerate([int(x) for x in input().split()], 1)}
	zoms = [int(x) for x in input().split()]
	sum_ls = [0 for _ in range(N + 1)]
	for cave in powers.keys():
		if cave - powers[cave] <= 1:
			lower = 1
		else:
			lower = cave - powers[cave]
		if cave + powers[cave] >= N:
			upper = N
		else:
			upper = cave + powers[cave]
		sum_ls[lower - 1] += 1
		sum_ls[upper] -= 1
	for x in range(1, N + 1):
		sum_ls[x] += sum_ls[x - 1]
	reverse_levels = collections.Counter(sum_ls[0:N])
	for health in zoms:
		if reverse_levels.get(health, 0) <= 0:
			flag = 1
			break
		else:
			reverse_levels[health] -= 1
	print('NO' if flag == 1 else 'YES')


for _ in range(int(input())):
	n = int(input())
	C = [int(i) for i in input().split(' ')]
	H = [int(i) for i in input().split(' ')]
	ans = [0] * (n + 2)
	for i in range(1, n + 1):
		lb = max(1, i - C[i - 1])
		ub = min(n, i + C[i - 1])
		ans[lb] += 1
		ans[ub + 1] -= 1
	for i in range(1, n + 1):
		ans[i] += ans[i - 1]
	ans = ans[1:-1]
	print('YES') if sorted(H) == sorted(ans) else print('NO')


t = int(input())
while t:
	n = int(input())
	c = [int(i) for i in input().split()]
	h = [int(i) for i in input().split()]
	k = [0] * n
	for i in range(1, n + 1):
		l = i - c[i - 1]
		r = i + c[i - 1]
		if l <= 1:
			l = 1
		k[l - 1] = k[l - 1] + 1
		if r <= n - 1:
			k[r] = k[r] - 1
	for i in range(1, n):
		k[i] = k[i - 1] + k[i]
	if sorted(h) == sorted(k):
		print('YES')
	else:
		print('NO')
	t = t - 1


from sys import stdin
for _ in range(int(stdin.readline())):
	N = int(stdin.readline())
	C = list(map(int, stdin.readline().rstrip().split()))
	H = list(map(int, stdin.readline().rstrip().split()))
	da = [0] * (N + 1)
	for i in range(N):
		da[i - C[i] if i - C[i] >= 0 else 0] += 1
		da[i + C[i] + 1 if i + C[i] + 1 <= N else N] -= 1
	A = [0] * N
	A[0] = da[0]
	for i in range(1, N):
		A[i] = da[i] + A[i - 1]
	if sorted(A) == sorted(H):
		print('YES')
	else:
		print('NO')


t = int(input())
while t:
	if t == 0:
		break
	x = int(input())
	radiation_power = [int(i) for i in input().split()]
	zombie_health = [int(i) for i in input().split()]
	n = len(radiation_power)
	diff_array = [0] * (n + 1)
	radiation_level = [0] * n
	diff_array[0] = radiation_level[0]
	diff_array[n] = 0
	left_index = 0
	right_index = 0
	for i in range(1, len(radiation_power)):
		diff_array[i] = radiation_level[i] - radiation_level[i - 1]
	for i in range(len(radiation_power)):
		left_index = max(0, i - radiation_power[i])
		right_index = min(n - 1, i + radiation_power[i])
		diff_array[left_index] += 1
		diff_array[right_index + 1] -= 1
	for i in range(len(radiation_power)):
		if i == 0:
			radiation_level[i] = diff_array[i]
		else:
			radiation_level[i] = radiation_level[i - 1] + diff_array[i]
	if sorted(zombie_health) == sorted(radiation_level):
		print('YES')
	else:
		print('NO')
	t = t - 1


t = int(input())
while t > 0:
	n = int(input())
	l1 = list(map(int, input().split(' ')))
	l2 = list(map(int, input().split(' ')))
	sum0 = sum(l2)
	sum1 = 0
	for i in range(n):
		p = i - l1[i]
		k = i + l1[i]
		if p <= 0:
			p = 0
		if k >= n:
			k = n - 1
		sum1 += k - p + 1
	if sum0 == sum1:
		print('YES')
	else:
		print('NO')
	t -= 1


for _ in range(int(input())):
	(n, x) = (int(input()), 0)
	caves = list(map(int, input().split()))
	zombies = list(map(int, input().split()))
	rad = [0 for i in range(n + 2)]
	caves.insert(0, 0)
	result = []
	for i in range(1, n + 1):
		x = i - caves[i] if i - caves[i] >= 1 else 1
		y = i + caves[i] if i + caves[i] <= n else n
		rad[x] += 1
		rad[y + 1] -= 1
	x = 0
	for i in rad:
		x += i
		result.append(x)
	del result[0]
	del result[-1]
	print('YES' if sorted(zombies) == sorted(result) else 'NO')


d = int(input())
while d > 0:
	d -= 1
	n = int(input())
	c = list(map(int, input().split()))
	h = list(map(int, input().split()))
	f = 0
	for i in range(1, n + 1):
		a = i - c[i - 1]
		b = i + c[i - 1]
		if a <= 0:
			a = 1
		if b > n:
			b = n
		f = f + (b - a) + 1
	p = sum(h)
	if f != p:
		print('NO')
	else:
		print('YES')


def calculate_ranges(powers, no_of_caves):
	counter = 0
	levels = [0 for i in range(no_of_caves + 1)]
	for pow_i in range(1, no_of_caves + 1):
		max_range = no_of_caves if pow_i + powers[pow_i - 1] > no_of_caves else powers[pow_i - 1] + pow_i
		min_range = 1 if pow_i - powers[pow_i - 1] < 1 else pow_i - powers[pow_i - 1]
		levels[min_range - 1] += 1
		levels[max_range] -= 1
	return levels

def main():
	for _ in range(int(input())):
		no_of_caves = int(input())
		powers = list(map(int, input().split()))
		zombies = list(map(int, input().split()))
		levels = calculate_ranges(powers, no_of_caves)
		for i in range(1, no_of_caves):
			levels[i] += levels[i - 1]
		if sorted(levels[:no_of_caves]) == sorted(zombies):
			print('YES')
			continue
		print('NO')
main()