r/Competitive_Coding • u/Cool_Boy997 • Jul 10 '23
Coding help required.
Hello all, the link for the question is here:
https://codeforces.com/problemset/problem/1845/F
And my code in python is here:l, t = map(int, input().split())n = int(input())velocities = list(map(int, input().split()))
swimmers = list(range(n))positions = [0] * n
my_set = set(positions)
going_forward = Truecounter = 0meet = 0while counter < t:for i in swimmers:if going_forward:if positions[i] + velocities[i] >= l:positions[i] = lgoing_forward = Falseelif 0 <= positions[i]:positions[i] += velocities[i]if not going_forward: # This means that going_forward == Falseif positions[i] - velocities[i] <= 0:positions[i] = 0going_forward = Trueelif positions[i] <= l:positions[i] -= velocities[i]my_set = set(positions)if len(my_set) != len(positions):meet += 1counter += 1print(meet)
Could someone paste and/or explain the solution and/or tell me why i am wrong?