NetEase
1.
Violence 60%
2.
t = int(input().strip())
for _ in range(t):
n, m = map(int, input().strip().split())
a = list(map(int, input().strip().split()))
flag = True
for i in range(n):
res = a[i] - i
m += res
if m < 0:
flag = False
break
print('YES' if flag else 'NO')
3.
The second sample output: NO
Over 30%+timeout
t = int(input().strip())
for _ in range(t):
n, k = map(int, input().strip().split())
a = list(map(int, input().strip().split()))
reach = [-1] * n
queue = [0]
while queue:
tmp = queue.pop(0)
reach[tmp] = 1
for i in range(tmp+1, tmp+k+1):
if i < n:
if a[i] <= a[tmp]:
queue.append(i)
else:
reach[i] = 0
flag = reach[-1] == 1
super_candi = [i for i in range(n) if reach[i] == 0]
for candi in super_candi:
new_reach = reach[:]
new_queue = [candi]
while new_queue:
tmp = new_queue.pop(0)
new_reach[tmp] = 1
for i in range(tmp+1, tmp+k+1):
if i < n and a[i] <= a[tmp]:
new_queue.append(i)
flag = flag or new_reach[-1] == 1
print('YES' if flag else 'NO')
4.
analysis:
60% of the direct two-layer cycle, timeout
Du Xiaoman
1.
2.
9%
3.