-
-
Save avijitagarwal/c54b4db891017a44831e605da50a9ddb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
#define int long long | |
pair<int, int> getWinner(int N, int M, int K) { | |
if (N <= 2 * K) return {N, M}; | |
int start = M * 2 + K + 1, end = M + K << 1; | |
int x = max(0ll, (N - end) / K); | |
if (N - x * K > end) ++x; | |
int can = N - x * K, marks = min(M, end - can >> 1); | |
pair<int, int> winner = {can, marks}; | |
for (int i = 1; start <= N; ++i) { | |
x = max(0ll, (N - end) / K); | |
if (N - x * K > end) ++x; | |
can = N - x * K; marks = min(M, end - can >> 1); | |
if (can >= start and can <= end) { | |
winner = {can, marks}; | |
} | |
start += K * (1ll << i); | |
end = start + K - 1; | |
} | |
return winner; | |
} | |
main() { | |
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); | |
int i, j, k; | |
int tc; cin >> tc; | |
while(tc--) { | |
int N, M, K; cin >> N >> M >> K; | |
pair<int, int> winner = getWinner(N, M, K); | |
cout << winner.first << " " << winner.second << "\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment