Created
June 27, 2016 13:22
-
-
Save developer-sdk/fc6c442622e170f6b84d572bf8dce21d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class Koi_Align { | |
public static void main(String[] args) { | |
Scanner in = new Scanner(System.in); | |
int n = in.nextInt(); | |
int[] array = new int[n]; | |
for (int i = 0; i < n; i++) { | |
array[i] = in.nextInt(); | |
} | |
in.close(); | |
// 테스트용 데이 | |
// int[] array = { 5, 2, 4, 1, 3 }; | |
// int[] array = { 5, 2, 3, 4, 7, 1, 6 }; | |
int maxSequence = 0; | |
int[] sequence = new int[array.length + 1]; | |
sequence[array[0]] = 1; | |
for (int i = 1; i < array.length; i++) { | |
int pivot = array[i]; | |
sequence[pivot] = sequence[pivot - 1] + 1; | |
maxSequence = Math.max(maxSequence, sequence[pivot - 1] + 1); | |
} | |
System.out.println(array.length - maxSequence); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment