1. GBC
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());
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
int[][] standard = new int[N][N];
int[][] test =new int[M][M];
ArrayList<Integer> difList = new ArrayList<>();
for(int i=0; i<N; i++){
st = new StringTokenizer(br.readLine());
int distance = Integer.parseInt(st.nextToken());
int limit = Integer.parseInt(st.nextToken());
standard[i][0] = distance;
standard[i][1] = limit;
}
for(int i=0; i<M; i++){
st = new StringTokenizer(br.readLine());
int distance = Integer.parseInt(st.nextToken());
int limit = Integer.parseInt(st.nextToken());
test[i][0] = distance;
test[i][1] = limit;
}
int idx = 0;
for(int i=0; i<N; i++){
for(int j=idx; j<M; j++){
if(standard[i][0] < test[j][0] ){
test[j][0] -= standard[i][0]; // 60-50
difList.add(test[j][1] - standard[i][1]);
break;
}else if(standard[i][0] > test[j][0] ){
standard[i][0] -= test[j][0]; // 40-10
difList.add(test[j][1] - standard[i][1]);
idx++;
}
else{
difList.add(test[j][1] - standard[i][1]);
idx++;
break;
}
}
}
Collections.sort(difList, Collections.reverseOrder());
System.out.println(difList.get(0));
}
}
구간마다의 거리"차"를 로직에 맞게 계산하는식으로 풀어야한다.
'Softeer 풀이' 카테고리의 다른 글
[Sofreer 문제풀이] Lv.2(성적 평균) feat. Java (0) | 2023.11.03 |
---|---|
[Sofreer 문제풀이] Lv.2(8단 변속기) feat. Java (0) | 2023.10.29 |
[Sofreer 문제풀이] Lv.1(주행거리 비교하기, 근무시간 A+B) feat. Java (0) | 2023.10.25 |