아직 계정이 없으신가요? 회원가입

Dev. Talk

GBC 반례 질문

회원사진squall0420
80 views2023-01-02 11:25

아래 코드 10개 테스트 케이스 중 두번째 것만 오답이라고 뜨는데

반례 어떤게 있을까요?



import java.util.*;
import java.io.*;


public class Main
{
    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);
	int m = sc.nextInt();
	int n = sc.nextInt();
	int[] limit_dis = new int[m];
	int[] limit_spd = new int[m];
	int[] real_dis = new int[n];
	int[] real_spd = new int[n];
	int max = 0;
		
	for (int i = 0; i < m; i++) {
		limit_dis[i] = sc.nextInt();
		limit_spd[i] = sc.nextInt();
	}
			
	for (int i = 0; i < n; i++) {
		real_dis[i] = sc.nextInt();
		real_spd[i] = sc.nextInt();
	}
		
	int i = 0;
	int j = 0;
	int remain = 1;
	max = real_spd[j] - limit_spd[i];
	remain = limit_dis[i] - real_dis[j];
	while(i < m && j < n) {
		if (remain > 0) {
			j++;
			remain = remain - real_dis[j];
		}else if (remain < 0){
			i++;
			remain = remain + limit_dis[i];
		}else {
			//break;
			j++;
			i++;
			if (i >= m && j >=n) break;
			else remain = limit_dis[i] - real_dis[j];
		}
		if (max < (real_spd[j] - limit_spd[i])) max = real_spd[j] - limit_spd[i];  
	}
	System.out.println(max);
    }
}