https://www.acmicpc.net/problem/19637
나의풀이
import java.io.*;
import java.util.*;
public class Main {
public static void main(String args[]) throws Exception{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st= new StringTokenizer(br.readLine());
int n= Integer.parseInt(st.nextToken());
int m= Integer.parseInt(st.nextToken());
String[] slist= new String[n];
int[] ilist = new int[n];
for(int i=0;i<n;i++){
st= new StringTokenizer(br.readLine());
slist[i]=st.nextToken();
ilist[i]=Integer.parseInt(st.nextToken());
}
for(int i=0; i<m; i++){
st= new StringTokenizer(br.readLine());
int temp = Integer.parseInt(st.nextToken());
//이진탐색
int start=0;
int end= n-1;
int mid=0;
while(start<=end){
mid=(start+end)/2;
if(ilist[mid] < temp){
start=mid+1;
}else{
end=mid-1;
}
}
bw.write(slist[end+1]+"\n");
}
bw.flush();
br.close();
bw.close();
}
}
'코테풀이' 카테고리의 다른 글
[백준] BOJ - 20922 겹치는 건 싫어 자바 java (실버 1) (0) | 2023.03.12 |
---|---|
[백준] BOJ - 14940 쉬운 최단거리 자바 java (실버1) (0) | 2023.03.10 |
[백준] BOJ - 2531 회전 초밥 자바 java (실버1) (0) | 2023.03.02 |
[백준] BOJ - 15989 1, 2, 3 더하기 4 자바 java (실버1) (0) | 2023.03.02 |
[백준] BOJ - 20310 타노스 자바 java (실버3) (0) | 2023.02.28 |