-
Notifications
You must be signed in to change notification settings - Fork 0
/
1491C.py
49 lines (46 loc) · 932 Bytes
/
1491C.py
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
def jump(i):
global a
ans=0
step=i
while step<n:
if a[step]>1:
ans+=1
step+=a[step]
else:
step+=a[step]
return ans
def chng(i):
global a
step=i
while step<n:
if a[step]>1:
t=step
step+=a[step]
a[t]-=1
else:
step+=a[step]
return a
for t in range(int(input())):
n=int(input())
a=[int(k) for k in input().split()]
if n==1:
print(a[0]-1)
# pas=0
# ans=0
# mxi=0
# while sorted(a)[-2]>1:
# pas+=1
# for i in range(n):
# if jump(i)>ans:
# ans=jump(i)
# mxi=i
# print(mxi)
# print(jump(mxi))
# a=chng(mxi)
# print(a)
# pas+=sorted(a)[-1]-1
# print(pas)
if sorted(a)[-2]==1:
print(sorted(a)[-1]-1)
else:
print(sorted(a)[-1])