https://www.acmicpc.net/problem/19637
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
StringBuilder sb = new StringBuilder();
int n = Integer.parseInt(st.nextToken());
int m = Integer.parseInt(st.nextToken());
String[] name = new String[n];
int[] power = new int[n];
for (int i = 0; i < n; i++) {
st = new StringTokenizer(br.readLine());
name[i] = st.nextToken();
power[i] = Integer.parseInt(st.nextToken());
}
for (int i = 0; i < m; i++) {
int low = 0;
int high = power.length - 1;
int num = Integer.parseInt(br.readLine());
while (low <= high) {
int mid = (low + high) / 2;
if (power[mid] < num) {
low = mid + 1;
} else {
high = mid - 1;
}
}
sb.append(name[low]);
sb.append("\n");
}
System.out.println(sb);
}
}
1. 아래 사항들의 사용이 낯설었음
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
StringBuilder sb = new StringBuilder();
2. 이진탐색 완료 후 name 배열의 인덱스 low 혹은 high+1이 정답이라는 사실에 유의