Why Am I getting Jumping Cost(JUMPCOST) Wrong?

My code
for _ in range(int(input())):
    X = int(input())
    A = list(map(int, input().split()))
    balance = 0
    prev_index = 1
    next_index = 0
    index = 2
    current = 0
    maxx = 0
    while index <= X:
        for i in range(index - 1, X):
            current = (A[i] - (i + 1)) + (prev_index - 1)
            if current > maxx:
                maxx = current
            current = 0
            balance += maxx
            next_index = i + 1
        prev_index = next_index
        index += 1
        maxx = 0
    print(balance)

I would be appreciated if you could help me on this.

What kind of an error are u getting?WA, TLE, Runtime error…ext?

WA

im not too sure but whenever i use a for loop inside a while loop it doesn’t seem to work so maybe something to do with that.

Sometimes they do work. There should be a WA somewhere…

idk then, maybe u should get ai find error help

that’s what I know that

You do understand the problem right?

I cant get it right though

Just asking if you knew what the question meant. I know that the technique is Greedy, and this one doesn’t look like bigger is always better, so made the code like this. Can you help me like in at least choosing the formula I have to write?

I have visulized your code but can’t seem to find the error but I suspect it is in the line:

100% I guarantee it’s not the formula. That’s the balance you’ll get when you jump from one index to another. Although the variable gives me a doubt.

Also, the while for loop isn’t wrong, but something inside it is guaranteed wrong