1548번: 부분 삼각 수열
Difficulty : Gold V
Problem Description
There are three numbers. If one is less than the sum of others, they are triangle.
Triangular sequence is a sequence that every three elements are triangle.
The input is the length of sequence 'N', and the sequence.
The output is length of the longest triangular sequence that can be made up of input sequence.
Solution
I calculated all cases that can be made by using the input sequence because the maximum length is just 50.
'N' is the length of input sequence.
'l' is the sequence, and sort it to calculate.
'm' is the length of longest triangular sequence.
'i' is the length of the sequence for each repetition.
'j' is the start index of the sequence.
To judge whether the sequence is triangular, I just need to compare the sum of the smallest two numbers to the largest number.
Compare the sum of the first number and the second number to the last number because the list is already sorted before.
If the sum is bigger than the last number, it is triangular. Find the maximum length while repeating the for statement.
여담
자랑을 좀 하자면 처음으로 숏코딩 1등을 하게 되었다.(지금까지 1페이지에도 든적이 없었는데...)
문제를 푼 사람이 적어서 가능했던 일이지만
처음으로 랭킹에 등재되었다는 것에 의의를 두기로 했다.