• 문제 링크
https://www.acmicpc.net/problem/34200
• 풀이 코드
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
public class Main {
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int n = read(), a = 0, sum = 0;
while (n-- > 0) {
int b = read();
if (a == b) break;
sum += (b - a) / 2 + 1;
a = b + 1;
}
bw.write(n == -1 ? String.valueOf(sum) : "-1");
bw.flush();
}
private static int read() throws IOException {
int c, n = System.in.read() & 15;
while ((c = System.in.read()) > 32) n = (n << 3) + (n << 1) + (c & 15);
return n;
}
}
'Problem Solving > Baekjoon' 카테고리의 다른 글
[백준] 16431 베시와 데이지 - Implementation / Java (0) | 2025.08.31 |
---|---|
[백준] 3035 스캐너 - Implementation / Java (0) | 2025.08.30 |
[백준] 30350 Dviratininkas - Greedy / Java (0) | 2025.08.28 |
[백준] 26753 OIJ - Greedy / Java (0) | 2025.08.27 |
[백준] 3279 DOLLARS - Greedy / Java (0) | 2025.08.26 |
댓글