Advertisement
fedoseevtimofey

Untitled

Jan 16th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.50 KB | None | 0 0
  1. n, k, x, y = map(int, input().split())
  2.  
  3. num = n // k * x + (n - n // k) * y
  4.  
  5. q = int(input())
  6. quer = list(map(int, input().split()))
  7. for i in range(q):
  8.     quer[i] -= 1
  9.  
  10. def ans(a):
  11.     kv = a % num
  12.     in_block = (k - 1) * y + x
  13.     num_block = kv // in_block
  14.     num_in_block = kv % in_block
  15.     if num_in_block >= (k - 1) * y:
  16.         floor_in_block = k
  17.     else:
  18.         floor_in_block = num_in_block // y + 1
  19.     return num_block * k + floor_in_block
  20.  
  21. for i in quer:
  22.     print(ans(i))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement