Source Code
import math
tmp = input().split(" ")
n = int(tmp[0])
k = int(tmp[1])
a = input().split(" ")
b = [0]*n
for i in range(0,n):
    b[i] = int(a[i])
suma = 0
for i in range(0,n):
    suma += int(a[i])



ans = (-1 + math.sqrt(1 - 4*(-2*k/suma) ))/2

for i in range(0,n):
    a[i] = int(ans) * int(a[i]) + b[i]
    
if(ans-int(ans) == 0):
    print(int(ans))
    exit()

if(ans % 2 == 0):
    for i in range(n-1,0,-1):
            if(k >= int(a[i])):
                k -= int(a[i])
                ans +=1

else:
    for i in range(n-1,0,-1):
        if(k >= int(a[i])):
             k -= int(a[i])
             a[i] = str(int(b[i]) + int(a[i]))
             ans +=1


print(ans)
Copy
Saqqa 26/40 SilverCryptor
Python 3
17 ms
2.9 MB
Wrong Answer