-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2184B.cpp
More file actions
37 lines (29 loc) · 837 Bytes
/
2184B.cpp
File metadata and controls
37 lines (29 loc) · 837 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <bits/stdc++.h>
using namespace std;
#define fast_io ios::sync_with_stdio(false); cin.tie(nullptr);
int main() {
fast_io;
int t;
cin >> t;
while (t--) {
long long s, k, m;
cin >> s >> k >> m;
long long flips = m / k;
long long t_since_last = m % k;
long long remaining_at_last_flip;
if (s < k) {
remaining_at_last_flip = s;
} else if (s == k) {
remaining_at_last_flip = s;
} else {
if (flips % 2 == 0) {
remaining_at_last_flip = s;
} else {
remaining_at_last_flip = k;
}
}
long long answer = max(0LL, remaining_at_last_flip - t_since_last);
cout << answer << "\n";
}
return 0;
}