Skip to content

Commit 8c4ec3d

Browse files
authored
[20250810] BOJ / G5 / 두 배 더하기 / 김수연
1 parent f0bfbf6 commit 8c4ec3d

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class boj12931 {
6+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
static StringTokenizer st;
8+
static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());}
9+
static int nextInt() {return Integer.parseInt(st.nextToken());}
10+
11+
public static void main(String[] args) throws Exception {
12+
nextLine();
13+
int N = nextInt();
14+
nextLine();
15+
int add = 0, multi = 0;
16+
for (int i = 0; i < N; i++) {
17+
int b = nextInt();
18+
int cnt = 0;
19+
while (b > 0) {
20+
if (b % 2 == 1) {
21+
b--;
22+
add++;
23+
} else {
24+
b /= 2;
25+
cnt++;
26+
}
27+
}
28+
multi = Math.max(multi, cnt);
29+
}
30+
System.out.println(add + multi);
31+
}
32+
}
33+
```

0 commit comments

Comments
 (0)