Chase Secret Issue - OBI 2017

1

I'm solving the following OBI problem: link

Secret of the safe The secret system for opening this safe is quite complex. Instead of turning a button several times, as you usually see in the movies, the owner of the safe has to slide a control left and right, over a bar, several times, stopping at certain positions. The bar has N positions and each position contains an integer between 0 and 9 inclusive. In the figure example, the bar has 14 positions and the control is in position 1.

The secret will depend on how often each of the ten integers between 0 and 9 will appear within the control. For example, assume that the owner slides the control from start position 1 to position 9, then to position 4, then to position 11 and finally to position 13. See that the integer 1, for example, will appear six times within control; and the integer 9 will appear four times.

Given the sequence of integers in the slash and the sequence of positions between which the owner slides the control, starting from initial position 1, your program must count how many times each integer, between 0 and 9, will appear inside the control.

Entrance The first line of the entry contains two integers N and M, representing the number of positions in the bar of the safe and the number of positions in the sequence that the owner will follow to slide the control. The second line contains N integers between 0 and 9, defining the bar of the chest. The third line contains M integers representing the sequence of positions that the owner will follow. The first position in this sequence is always 1 and no two consecutive positions are equal. Output Your program should print a line containing 10 integers, representing the number of times that each integer, between 0 and 9, will appear in the bar control. Restrictions 2 ≤ N ≤ 105 and 2 ≤ M ≤ 105 Punctuation information In a set of tests summing 40 points, N ≤ 1000 and M ≤ 1000

Here's my code: link

N, M = input().split(" ")
N, M = int(N), int(M)
cfo = input().split(" ")
for x in range(N): cfo[x] = int(cfo[x])
cfs = input().split(" ")
for x in range(M): cfs[x] = int(cfs[x])
cfi = []
cfp = []
for x in cfs:
    for y in range(x):
        cfi.append(cfo[y])
print(cfi)
for x in range(10):
    cfp.append(cfi.count(x))
print(cfp)

My problem is to go through the list, for example if something goes to position 5 in the list, and the next one has to go to 6, it runs only one position, but my program is running 7 positions (counting on 0 ), every time it restarts.

How could I solve this?

    
asked by anonymous 15.05.2018 / 15:51

0 answers