-
[Softeer] GBC (lv.2)ALGORITHM/SWEXPERT|SOFTEER 2021. 11. 2. 22:44
https://softeer.ai/practice/info.do?eventIdx=1&psProblemId=584
2021
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950import java.util.*;import java.io.*;public class Main{public static int N, M;public static void main(String[] args) throws IOException {BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));StringTokenizer st = new StringTokenizer(bf.readLine());N = Integer.parseInt(st.nextToken());M = Integer.parseInt(st.nextToken());int[][] arr = new int[N][2];int answer = 0;for(int i = 0; i < N; i++) {st = new StringTokenizer(bf.readLine());arr[i][0] = Integer.parseInt(st.nextToken());arr[i][1] = Integer.parseInt(st.nextToken());}int[][] speed = new int[M][2];for(int i = 0; i < M; i++) {st = new StringTokenizer(bf.readLine());speed[i][0] = Integer.parseInt(st.nextToken());speed[i][1] = Integer.parseInt(st.nextToken());}int idx = 0;for(int i = 0; i < N; i++) {for(int j = idx; j < M; j++) {if(arr[i][0] < speed[j][0]) {speed[j][0] -= arr[i][0];if(speed[j][1] - arr[i][1] > 0) answer = Math.max(answer, speed[j][1] - arr[i][1]);break;} else if(arr[i][0] > speed[j][0]) {arr[i][0] -= speed[j][0];if(speed[j][1] - arr[i][1] > 0) answer = Math.max(answer, speed[j][1] - arr[i][1]);idx++;} else {if(speed[j][1] - arr[i][1] > 0) answer = Math.max(answer, speed[j][1] - arr[i][1]);idx++;break;}}}System.out.println(answer);}}cs 'ALGORITHM > SWEXPERT|SOFTEER' 카테고리의 다른 글
[Softeer] 스마트 물류 (lv.3) (0) 2021.11.02 [Softeer] 동계 테스트 시점 예측 (lv.3) (0) 2021.11.02 [Softeer] 장애물 인식 프로그램 (lv.2) (0) 2021.11.02 [Softeer] 8단 변속기 (lv.2) (0) 2021.11.02 [Softeer] 바이러스 (lv.2) (0) 2021.11.02