개발자 톡

연습문제 톡 GBC

GBC 반례 찾아주실 수 있을까요?

등록일
2023-07-03 22:18:49
조회수
409
작성자
hiyoojeong

class Section {

int start;

int end;

int limitSpeed;


Section(int start, int end, int limitSpeed) {

this.start = start;

this.end = end;

this.limitSpeed = limitSpeed;

}


public boolean isContain(int section) {

if (section > start && section <= end)

return true;

return false;

}


public int getOverSpeed(int testSpeed) {

return testSpeed - limitSpeed;

}

}


public class Main {


public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

int N = scanner.nextInt();

int M = scanner.nextInt();


int start;

int max = 0;


// 엘레베이터 구간마다 제한 속도 정보 저장

start = 0;

Section[] limit = new Section[N];

for (int i = 0; i < N; i++) {

int end = start + scanner.nextInt();

int limitSpeed = scanner.nextInt();


limit[i] = new Section(start, end, limitSpeed);

start = end;

}


// 테스트 구간에서 제한 속도를 벗어나는 경우 탐색

start = 0;

for (int i = 0; i < M; i++) {

int end = start + scanner.nextInt();

int testSpeed = scanner.nextInt();


for (int j = 0; j < N; j++) {

if (limit[j].isContain(start + 1) || limit[j].isContain(end)) {

int overSpeed = limit[j].getOverSpeed(testSpeed);

if (max < overSpeed)

max = overSpeed;

}

}

start = end;

}


scanner.close();


System.out.println(max);


}

}


테스트케이스 열 개 중에 하나만 틀리는데 뭐가 문제일까요?ㅠㅠ

#gbc
#java

이 카테고리의 톡 더보기