CF2_kafuma's blog

By CF2_kafuma, history, 3 years ago, In English,

that's my code , and i can't understand why i have RUNTime_Error?? can someone explain me??

Limite = input();
Valores = map(int, raw_input().split());
Permutacion = map(lambda x: int(x) - 1, raw_input().split());

Rpta = [0];
Visitado = [False]*Limite;
DSU = range(Limite);
DSUValor = [0]*Limite;


def Find(posicion):
    if posicion != DSU[posicion]:
        DSU[posicion] = Find(DSU[posicion]);
    return DSU[posicion];


def Union(A, B):
    Pos_A = Find(A);
    Pos_B = Find(B);
    DSU[Pos_B] = Pos_A;
    DSUValor[Pos_A] += DSUValor[Pos_B];


for x in reversed(Permutacion):
    Visitado[x] = True;
    DSUValor[ x ] = Valores[ x ];
    if x - 1 >= 0 and Visitado[x - 1]:
        Union(x, x - 1);
        #Valores[ x ] += Valores[ Find( x -1 ) ];
        #DSU[ Find( x - 1 ) ] = x;
    if x + 1 < Limite and Visitado[x + 1]:
        Union(x, x + 1);
        #Valores[x] += Valores[Find(x + 1)];
        #DSU[Find(x + 1)] = x;
    #DSUValor[x] += Valores[x];
    Rpta.append(max( Rpta[-1], DSUValor[x]));

print '\n'.join(map(str, reversed(Rpta[:-1 ])));
 
 
 
 
  • Vote: I like it
  • -2
  • Vote: I do not like it

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by CF2_kafuma (previous revision, new revision, compare).