Skip to content

Commit 6f3018e

Browse files
committed
🪙 S2-18353
1 parent fc7ab80 commit 6f3018e

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

🪙 S2/18353.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from bisect import bisect_left
2+
3+
n = int(input())
4+
a = list(reversed(list(map(int, input().split()))))
5+
dp = [1]
6+
x = [a[0]]
7+
8+
for i in range(1, n):
9+
if a[i] > x[-1]:
10+
x.append(a[i])
11+
dp.append(dp[-1]+1)
12+
else:
13+
idx = bisect_left(x, a[i])
14+
x[idx] = a[i]
15+
16+
print(n-dp[-1])

0 commit comments

Comments
 (0)