Skip to content

Commit a2b07c2

Browse files
Shovels and Swords
1 parent a992f5e commit a2b07c2

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

1366/A/Main.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import java.util.Scanner;
2+
3+
public class Main {
4+
public static void main(String[] args) {
5+
Scanner sc = new Scanner(System.in);
6+
7+
int t = sc.nextInt();
8+
for (int tc = 0; tc < t; ++tc) {
9+
int a = sc.nextInt();
10+
int b = sc.nextInt();
11+
12+
System.out.println(solve(a, b));
13+
}
14+
15+
sc.close();
16+
}
17+
18+
static int solve(int a, int b) {
19+
int common = Math.min(a, b);
20+
int extra = a + b - common * 2;
21+
22+
if (extra >= common) {
23+
return common;
24+
}
25+
26+
return extra + (common - extra) / 3 * 2 + (((common - extra) % 3 == 2) ? 1 : 0);
27+
}
28+
}

0 commit comments

Comments
 (0)