Problem p03138 (python)

Fixed submission:
import math
def main():
  N, K = list(map(int, input().split()))
  A = list(map(int, input().split()))
 
  if K == 0:
    C = 0
  else:
    C = int(math.log2(K + 1))
  L = [[0 for i in range(44)] for j in range(C + 1)]
 
  for i in A:
    for j in range(len(L[0])):
      if i % 2 == 1:
        i -= 1
        L[0][j] += 1
      if i == 0:
        break
      i /= 2
  for i in range(1, C + 1):
    for j in range(44):
      L[i][j] = L[0][j]
 
  x = pow(2, C)
  T = [K for i in range(C + 1)]
  for i in range(C, -1, -1):
    for j in range(C + 1):
      if T[j] >= x:
        if j != i and L[j][i] <= N / 2:
          L[j][i] = N - L[j][i]
          T[j] -= x
    x //= 2
 
  Ans = [0 for i in range(C + 1)]
  x = 1
  for i in range(44):
    for j in range(C + 1):
      Ans[j] += L[j][i] * x
    x *= 2
 
  print(max(Ans))

main()

Buggy submission (verdict: Runtime Error):
import math
def main():
  N, K = list(map(int, input().split()))
  A = list(map(int, input().split()))
 
  if K == 0:
    C = 0
  else:
    C = int(math.log2(K + 1))
    L = [[0 for i in range(44)] for j in range(C + 1)]
 
    for i in A:
      for j in range(len(L[0])):
        if i % 2 == 1:
          i -= 1
          L[0][j] += 1
        if i == 0:
          break
        i /= 2
    for i in range(1, C + 1):
      for j in range(44):
        L[i][j] = L[0][j]
 
    x = pow(2, C)
    T = [K for i in range(C + 1)]
    for i in range(C, -1, -1):
      for j in range(C + 1):
        if T[j] >= x:
          if j != i and L[j][i] <= N / 2:
            L[j][i] = N - L[j][i]
            T[j] -= x
      x //= 2
 
    Ans = [0 for i in range(C + 1)]
    x = 1
    for i in range(44):
      for j in range(C + 1):
        Ans[j] += L[j][i] * x
      x *= 2
 
  print(max(Ans))

main()

Buggy submission (verdict: Runtime Error):
import math
def main():
  N, K = list(map(int, input().split()))
  A = list(map(int, input().split()))
 
  if K == 0:
    C = 0
  else:
    C = int(math.log2(K + 1))
    L = [[0 for i in range(50)] for j in range(C + 1)]
 
    for i in A:
      for j in range(len(L[0])):
        if i % 2 == 1:
          i -= 1
          L[0][j] += 1
        if i == 0:
          break
        i /= 2
    for i in range(1, C + 1):
      for j in range(50):
        L[i][j] = L[0][j]
 
    x = pow(2, C)
    T = [K for i in range(C + 1)]
    for i in range(C, -1, -1):
      for j in range(C + 1):
        if T[j] >= x:
          if j != i and L[j][i] <= N / 2:
            L[j][i] = N - L[j][i]
            T[j] -= x
      x //= 2
 
    Ans = [0 for i in range(C + 1)]
    x = 1
    for i in range(50):
      for j in range(C + 1):
        Ans[j] += L[j][i] * x
      x *= 2
 
  print(max(Ans))

main()

Buggy submission (verdict: Runtime Error):
import math

def main():
  N, K = list(map(int, input().split()))
  A = list(map(int, input().split()))
  
  if K == 0:
    C = 0
  else:
    C = int(math.log2(K + 1))
  
  Lt = [0 for i in range(44)]
  for i in A:
    t = i
    for j in range(len(Lt)):
      if t % 2 == 1:
        t -= 1
        Lt[j] += 1
      if t == 0:
        break
      t /= 2
  
  L = [Lt for i in range(C + 1)]
  
  x = pow(2, C)
  T = [K for i in range(C + 1)]
  for i in range(C, -1, -1):
    for j in range(C + 1):
      if T[j] >= x:
        if j != i and L[j][i] <= N / 2:
          L[j][i] = N - L[j][i]
          T[j] -= x
    x //= 2
  
  Ans = [0 for i in range(C + 1)]
  x = 1
  for i in range(44):
    for j in range(C + 1):
      Ans[j] += L[j][i] * x
    x *= 2
  
  print(max(Ans))
  
main()

Buggy submission (verdict: Runtime Error):
import math

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

if K == 0:
  C = 0
else:
  C = int(math.log2(K + 1))
Lt = [0 for i in range(44)]

for i in A:
  t = i
  for j in range(len(Lt)):
    if t % 2 == 1:
      t -= 1
      Lt[j] += 1
    if t == 0:
      break
    t /= 2

L = [Lt for i in range(C + 1)]

x = pow(2, C)
T = [K for i in range(C + 1)]
for i in range(C, -1, -1):
  for j in range(C + 1):
    if T[j] >= x:
      if j != i and L[j][i] <= N / 2:
        L[j][i] = N - L[j][i]
        T[j] -= x
  x //= 2

Ans = [0 for i in range(C + 1)]
x = 1
for i in range(44):
  for j in range(C + 1):
    Ans[j] += L[j][i] * x
  x *= 2

print(max(Ans))

Buggy submission (verdict: Runtime Error):
import math

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

if K == 0:
  C = 0
else:
  C = int(math.log2(K + 1))
L = [[0 for i in range(44)] for j in range(C + 1)]

for i in A:
  t = i
  for j in range(len(L[0])):
    if t % 2 == 1:
      t -= 1
      L[0][j] += 1
    if t == 0:
      break
    t /= 2
for i in range(1, C + 1):
  for j in range(44):
    L[i][j] = L[0][j]

x = pow(2, C)
T = [K for i in range(C + 1)]
for i in range(C, -1, -1):
  for j in range(C + 1):
    if T[j] >= x:
      if j != i and L[j][i] <= N / 2:
        L[j][i] = N - L[j][i]
        T[j] -= x
  x //= 2

Ans = [0 for i in range(C + 1)]
x = 1
for i in range(44):
  for j in range(C + 1):
    Ans[j] += L[j][i] * x
  x *= 2

print(max(Ans))

Buggy submission (verdict: Runtime Error):
import math

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

if K == 0:
  C = 0
else:
  C = int(math.log2(K + 1))
L = [[0 for i in range(44)] for j in range(C + 1)]

for i in A:
  for j in range(len(L[0])):
    if i % 2 == 1:
      i -= 1
      L[0][j] += 1
    if i == 0:
      break
    i /= 2
for i in range(1, C + 1):
  for j in range(44):
    L[i][j] = L[0][j]

x = pow(2, C)
T = [K for i in range(C + 1)]
for i in range(C, -1, -1):
  for j in range(C + 1):
    if T[j] >= x:
      if j != i and L[j][i] <= N / 2:
        L[j][i] = N - L[j][i]
        T[j] -= x
  x //= 2

Ans = [0 for i in range(C + 1)]
x = 1
for i in range(44):
  for j in range(C + 1):
    Ans[j] += L[j][i] * x
  x *= 2

print(max(Ans))

Buggy submission (verdict: Runtime Error):
import math

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

if K == 0:
  C = 0
else:
  C = int(math.log2(K + 1))
L = [[0 for i in range(50)] for j in range(C + 1)]

for i in A:
  for j in range(len(L[0])):
    if i % 2 == 1:
      i -= 1
      L[0][j] += 1
    if i == 0:
      break
    i /= 2
for i in range(1, C + 1):
  for j in range(50):
    L[i][j] = L[0][j]

x = pow(2, C)
T = [K for i in range(C + 1)]
for i in range(C, -1, -1):
  for j in range(C + 1):
    if T[j] >= x:
      if j != i and L[j][i] <= N / 2:
        L[j][i] = N - L[j][i]
        T[j] -= x
  x //= 2

Ans = [0 for i in range(C + 1)]
x = 1
for i in range(50):
  for j in range(C + 1):
    Ans[j] += L[j][i] * x
  x *= 2

print(max(Ans))