Here a Pythonized solution without sorting. Fastest solution for Python.
for _ in xrange(input()):
n = input()
C = [0]+map(int, raw_input().split())
H = [0]+map(int, raw_input().split())
s = sum(min(n, i+c)-max(1, i-c)+1 for i,c in enumerate(C))
print "YES" if s==sum(H) else "NO"
Hey guys!
You are doing great job.
Just one suggestion, you can use more readable/understandable/proper variable names which may leads to understand code from editorials quickly.
I’m referring to ini_C, fin_C
Yeah. Thats not exactly in my bounds to control the variable names used by setter or tester. But I will take this feedback to keep better names in editorialist solution
I’m starting to sound like a jerk, here, but this is also incorrect Consider:
1
5
1 2 1 2 1
2 3 4 3 3
(I should probably point out that I have a long, long history of whining about weak testcases, so none of this is personal - it’s just one of my bugbears :
value of i-ini_c[i] might be <1 then we can’t update indexes that are less than 1
so we still need to update from index 1
so left bound=max(1,i-ini_c[i])
similarly the value of i+ini_c[i] might be >n then we can update only upto n
so right bound=min(n,i+ini_c[i])