-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtowers.py
More file actions
52 lines (40 loc) · 1.01 KB
/
towers.py
File metadata and controls
52 lines (40 loc) · 1.01 KB
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
50
51
52
import sys
# Fast I/O
input = sys.stdin.readline
# Common imports
from collections import defaultdict, deque, Counter
from itertools import combinations, permutations, product, accumulate
from functools import lru_cache, reduce
import heapq
import bisect
# Constants
MAX = float('inf')
MIN = float('-inf')
MOD = 10**9 + 7
# =======================
# Main Logic
# =======================
def solve():
n = int(input())
arr = list(map(int, input().split()))
values = []
for x in arr:
if not values or values[-1] <= x:
values.append(x)
else:
i,j = 0,len(values)-1
point = -1
while i <= j:
mid = (i+j)//2
if values[mid] > x:
point = mid
j = mid-1
else:
i = mid+1
values[point] = x
sys.stdout.write(str(len(values)))
# =======================
# Entry Point
# =======================
if __name__ == "__main__":
solve()