• 문제 링크
26042번: 식당 입구 대기 줄
첫 번째 정보부터 n번째 정보까지 순서대로 처리한 다음, 식당 입구에 줄을 서서 대기하는 학생 수가 최대가 되었던 순간의 학생 수와 이때 식당 입구의 맨 뒤에 대기 중인 학생의 번호를 빈칸을
www.acmicpc.net
• 풀이 코드
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.ArrayDeque;
import java.util.Queue;
public class Main {
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringBuilder sb = new StringBuilder();
Queue<Integer> q = new ArrayDeque<>();
int n = read(), i, max = 0, min = 100000;
while (n-- > 0) {
if (read() == 1) {
q.offer(i = read());
if (max < q.size()) {
max = q.size();
min = i;
} else if (max == q.size()) min = Math.min(min, i);
} else q.poll();
}
sb.append(max).append(" ").append(min);
bw.write(sb.toString());
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' 카테고리의 다른 글
[백준] 17287 The Deeper, The Better - Data Structure / Java (0) | 2023.10.11 |
---|---|
[백준] 28446 볼링공 찾아주기 - Data Structure / Java (0) | 2023.10.10 |
[백준] 30034 Slice String - Data Structure / Java (0) | 2023.10.08 |
[백준] 14235 크리스마스 선물 - Data Structure / Java (0) | 2023.10.07 |
[백준] 18268 Cow Gymnastics - Brute Force / Java (0) | 2023.10.06 |
댓글