-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHourGlass.java
More file actions
28 lines (27 loc) · 773 Bytes
/
HourGlass.java
File metadata and controls
28 lines (27 loc) · 773 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
import java.util.Scanner;
public class HourGlass {
public static void main(String[]args){
Scanner sc = new Scanner(System.in);
if (sc.hasNextInt()) {
int t = sc.nextInt();
while (t-- > 0) {
int s = sc.nextInt();
int k = sc.nextInt();
int m = sc.nextInt();
int q = m/k;
int r = m%k;
int ans;
if(k>=s){
ans = Math.max(0, s-r);
}else{
if(q%2 == 0){
ans = s - r;
}else{
ans = k - r;
}
}
System.out.println(ans);
}
}
}
}