728x90
반응형
SMALL
[소프티어] GBC 레벨2 자바 풀이 단순 구현
테케를 배열에 담기만 하면 되는 문제다.

문제 스펙

핵심소스
100개 배열 두개로 "속도-제한속도" 의 최대값을 구하면 된다
int max = 0;
for(int i=1; i<=totalH; i++){
if( max < (speed[i]-limit[i]) )
max = (speed[i]-limit[i]);
}
전체소스
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));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int m = Integer.parseInt(st.nextToken());
int limit[] = new int[101];
int h = 1;
for(int i=0; i<n; i++){
st = new StringTokenizer(br.readLine());
int a = Integer.parseInt(st.nextToken());
int b = Integer.parseInt(st.nextToken());
for(int j=h; j<=h+a-1; j++){
// System.out.println(j + " " + h + " " + b);
limit[j] = b;
}
h += a;
}
int speed[] = new int[101];
h = 1;
int totalH = 0;
for(int i=0; i<m; i++){
st = new StringTokenizer(br.readLine());
int a = Integer.parseInt(st.nextToken());
totalH += a;
int b = Integer.parseInt(st.nextToken());
for(int j=h; j<=h+a-1; j++){
// System.out.println(j + " " + h + " " + b);
speed[j] = b;
}
h += a;
}
int max = 0;
for(int i=1; i<=totalH; i++){
if( max < (speed[i]-limit[i]) )
max = (speed[i]-limit[i]);
}
bw.write(String.valueOf(max));
bw.close();
}
}
728x90
반응형
LIST
'알고리즘 단련장 > 소프티어' 카테고리의 다른 글
[소프티어] 회의실 예약 레벨2 자바 풀이 (21년 재직자 대회 예선) (0) | 2024.07.19 |
---|---|
[소프티어] 전광판 레벨2 자바 풀이 (21년 재직자 대회 예선) (5) | 2024.07.19 |
[소프티어] 비밀 메뉴 레벨2 자바 풀이 단순 구현 (21년 재직자 대회 예선) (0) | 2024.07.19 |
[소프티어] 진정한 효도 자바 풀이 레벨2 단순 구현 (0) | 2024.07.18 |
[소프티어] 장애물 인식 프로그램 dfs 자바 풀이 레벨2 (0) | 2024.07.18 |