Skip to content

Instantly share code, notes, and snippets.

@avijitagarwal

avijitagarwal/CLMARKS.py Secret

Created Jul 14, 2020
Embed
What would you like to do?
for tc in xrange(input()):
N, M, K = map(int, raw_input().split())
def getWinner(N, M, K):
if N <= 2 * K: return (N, M)
start, end = M * 2 + K + 1, M + K << 1
x = max(0, (N - end) / K)
while N - x * K > end: x += 1
candi = N - x * K
marks = end - candi >> 1
winner = (candi, marks)
i = 1
while start <= N:
x = max(0, (N - end) / K)
while N - x * K > end: x += 1
candi = N - x * K
marks = end - candi >> 1
if candi >= start and candi <= end:
winner = (candi, marks)
start += K * 2 ** i
end = start + K - 1
i += 1
return winner
winner = getWinner(N, M, K)
print winner[0], min(M, winner[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.