Pagini recente » Cod sursa (job #2712823) | Cod sursa (job #1895651) | Cod sursa (job #37242) | Cod sursa (job #2305558) | Cod sursa (job #2533131)
def read_gen(fname):
with open(fname, 'rt') as fin:
for line in fin:
for val in line.split():
yield int(val)
def bs(n, x, v):
step = 1
while step <= n: step <<= 1
pos = 0
while step > 0:
if pos + step <= n and v[pos + step] < x:
pos += step
step >>= 1
return pos + 1
def solve(n, a):
""" d[i] = sequence of length i ending in smallest possible value d[i]"""
d = [0 for _ in range(n + 1)]
max_pos = 0
for i in range(1, n + 1):
pos = bs(max_pos, a[i], d)
d[pos] = a[i]
if pos > max_pos: max_pos = pos
return max_pos
if __name__ == "__main__":
it = read_gen('scmax.in')
n = next(it)
a = [0 for _ in range(n + 1)]
for i in range(1, n + 1):
a[i] = next(it)
ans = solve(n, a)
with open('scmax.out', 'wt') as fout:
fout.write('{}\n'.format(ans))
for _ in range(ans):
fout.write('{} '.format(0))
fout.write('\n')