Java 로 풀어보는 알고리즘입니다. 📖
코딩테스트를 대비하여 JAVA1.8 부터 제공되는 함수형 API 는 사용하지 않았습니다.

문제 : https://www.algospot.com/judge/problem/read/CANDLESTICK

 

algospot.com :: CANDLESTICK

Candlestick Charts 문제 정보 문제 A candlestick chart, often abbreviated to candle chart, is a variation of a bar chart. It is mostly used to describe the price of a stock over time. You are using a simple candle chart which looks like above. Each ba

www.algospot.com

 

풀이입니다. 🤔

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int[][] intervals = new int[2000][2];
 
        int cases = scanner.nextInt();
        while (cases-- > 0) {
            int n = scanner.nextInt();
            for (int i = 0; i < n; ++i) {
                intervals[i][0= scanner.nextInt();
                intervals[i][1= scanner.nextInt();
            }
 
            int ret = 0;
            for (int i = 0; i < n; ++i) {
                int min = -1, max = Integer.MAX_VALUE;
                for (int day = 0, maxDay = n - i; day < maxDay; ++day) {
                    min = Math.max(min, intervals[i + day][0]);
                    max = Math.min(max, intervals[i + day][1]);
 
                    ret = Math.max(ret, (day + 1* (max - min));
                }
            }
            System.out.println(ret);
        }
    }
}
cs

 

 

이 포스트를 읽어주셔서 감사합니다. 🙇🏻‍♂️

반응형

'개발이야기 > 알고스팟' 카테고리의 다른 글

[DIAMOND] 다이아몬드  (0) 2022.01.06
[ENCODING] Encoding  (0) 2022.01.06
[KAKURO1] Kakuro I  (0) 2022.01.06
[FESTIVAL] 록 페스티벌  (0) 2022.01.06
[NOTE] Note  (0) 2022.01.06
Posted by N'