๊ธฐ๋ก๋ฐฉ

BOJ_11971 : ์†๋„ ์œ„๋ฐ˜ ๋ณธ๋ฌธ

CodingTest/Java

BOJ_11971 : ์†๋„ ์œ„๋ฐ˜

Soom_1n 2022. 12. 6. 03:42

๐Ÿ‘‰ ๋ฌธ์ œ๋งํฌ

 

11971๋ฒˆ: ์†๋„ ์œ„๋ฐ˜

์˜ˆ๋ฅผ ๋“ค์–ด ๋„๋กœ๊ฐ€ 3๊ตฌ์—ญ [(40km, 75km/h), (50km, 35km/h), (10km, 45km/h)] ์ด๊ณ . ์—ฐ์ •์ด๊ฐ€ ๋‹ฌ๋ฆฐ 3๊ตฌ์—ญ [(40km, 76km/h), (20km, 30km/h), (40km, 40km/h)] ์ด๋ผ๋ฉด, ์ฒ˜์Œ 0 ~ 40km ์˜์—ญ์—์„œ 1km/h ๋งŒํผ ์œ„๋ฐ˜ํ–ˆ์œผ๋‚˜ 60km ~ 90km ์‚ฌ์ด์—

www.acmicpc.net



๐Ÿ”ธ ๋ฌธ์ œ ๋ถ„์„ ๐Ÿ”ธ

  •  

๐Ÿ”ธ ์ฝ”๋“œ ๐Ÿ”ธ

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] arr = new int[100];
        int idx = 0;

        for (int i = 0; i < n; i++) {
            int len = sc.nextInt();
            int speed = sc.nextInt();
            for (int j = idx; j < idx + len; j++)
                arr[j] = speed;
            idx += len;
        }
        idx = 0;
        int max = 0;
        for (int i = 0; i < m; i++) {
            int len = sc.nextInt();
            int speed = sc.nextInt();
            for (int j = idx; j < idx + len; j++) {
                if (arr[j] < speed && speed - arr[j] > max) {
                    max = speed - arr[j];
                    break;
                }
            }
            idx += len;
        }
        System.out.println(max);
    }
}

๐Ÿ”ธ ์ฝ”๋“œ ํ•ด์„ ๐Ÿ”ธ

  • ๋ฆฌ์ŠคํŠธ์˜ ํฌ๊ธฐ๋ฅผ 100์œผ๋กœ ๊ฐ ๊ตฌ๊ฐ„ ๋ณ„ ์ œํ•œ์†๋„๋ฅผ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค.
  • ์ œํ•œ์†๋„์™€ ์‹ค์ œ ์ฃผํ–‰ ์†๋„์˜ ์ฐจ์ด ์ค‘ ์ตœ๋Œ€๊ฐ’์„ ์ถœ๋ ฅํ•œ๋‹ค.

๐Ÿ”ธ end ๐Ÿ”ธ

  • ๊ฑฐ๋ฆฌ๊ฐ€ 100์ดํ•˜์˜ ์ •์ˆ˜์ด๋ฏ€๋กœ ๋ฐฐ์—ด๋กœ ๊ฐ„๋‹จํžˆ ๋‚˜ํƒ€๋‚ผ ์ˆ˜ ์žˆ์–ด์„œ ํ’€์ดํ•  ์ˆ˜ ์žˆ์—ˆ๋‹ค.

728x90

'CodingTest > Java' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

BOJ_1269 : ๋Œ€์นญ ์ฐจ์ง‘ํ•ฉ  (0) 2022.12.06
BOJ_9733 : ๊ฟ€๋ฒŒ  (0) 2022.12.06
BOJ_24389 : 2์˜ ๋ณด์ˆ˜  (0) 2022.12.05
BOJ_3595 : ๋งฅ์ฃผ ๋ƒ‰์žฅ๊ณ   (0) 2022.12.05
BOJ_4158 : CD  (0) 2022.12.01