Skip to content

Instantly share code, notes, and snippets.

@avijitagarwal

avijitagarwal/CLMARKS.cpp Secret

Created Jul 14, 2020
Embed
What would you like to do?
#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
You can’t perform that action at this time.