알고리즘 단련장/소프티어

[소프티어] GBC 레벨2 자바 풀이 단순 구현

snapcoder 2024. 7. 19. 00:59
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