KickItLikeShika's blog

By KickItLikeShika, history, 4 years ago, In English

I'm not good at Python but i'm trying to learn it, when i always submit a solution to Codeforces i always get run time error, but if i made the same solution in c++ it's okay and accepted, and here is an example. This is the problem set: https://codeforces.com/problemset/problem/1206/B

and here is my solution, all is well in my terminal window but i get run time error even in the first test case, i submit PyPy 3.6 or Python 3.7.2, i tried both

n = int(input())
    # ls = []
    counter = 0
    i = 0
    for i in range(n):
        k = int(input())
        # ls.append(k)
        if k > 1:
            counter += (k - 1)
        elif k < -1:
            counter += abs((k + 1))
        else:
            counter += 1
    print(counter)

and thank you.

Full text and comments »

  • Vote: I like it
  • +5
  • Vote: I do not like it