Cod sursa(job #2756815)

Utilizator thinkphpAdrian Statescu thinkphp Data 2 iunie 2021 23:01:56
Problema Subsir crescator maximal Scor 0
Compilator py Status done
Runda Arhiva educationala Marime 0.87 kb
def solve():
    file2 = open("scmax.out","w")
    file = open("scmax.in","r")
    n = int(file.readline().split("\n")[0])
    V = [int(x) for x in file.readline().split(" ")]    
    L = [1] * (n + 1)
    print(V)
    for i in range(n - 2, -1, -1):
        max = 0
        for j in range(i+1, n):
            if V[j] > V[i] and L[j] > max:
                max = L[j]
        L[i] = 1+ max
    print(L)
    max = L[0]
    pos = -1
    for i in range(1,n):
        if L[i] > max:
           pos = i
           max = L[i]
    file2.write(str(max) + "\n")
    print(max, end = "\n")
    file2.write(str(V[pos]) + " ")
    print(V[pos],end=" ")
    i = pos + 1
    while i < n:
         if V[i] > V[pos] and L[i] == max - 1:
            file2.write(str(V[i]) + " ")
            print(V[i], end =" ")
            max -= 1
         i +=1
    print("\nSolved!")
def main():    
    solve()
main()