녕의 학습 기록
백준_1377 버블 소트 (버블정렬) 본문
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
public class BJ_1377 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
int i, max;
int n = Integer.parseInt(br.readLine());
mData[] arr = new mData[n];
for (i = 0; i < n; i++) {
arr[i] = new mData(Integer.parseInt(br.readLine()), i);
}
Arrays.sort(arr);
max = 0;
for (i = 0; i < n; i++) {
max = Math.max(arr[i].index - i, max);
}
System.out.println(sb.append(max + 1));
}
private static class mData implements Comparable<mData>{
int value;
int index;
public mData(int value, int index) {
this.value = value;
this.index = index;
}
@Override
public int compareTo(mData o) {
return this.value - o.value;
}
}
}
1377번: 버블 소트
첫째 줄에 N이 주어진다. N은 500,000보다 작거나 같은 자연수이다. 둘째 줄부터 N개의 줄에 A[1]부터 A[N]까지 하나씩 주어진다. A에 들어있는 수는 1,000,000보다 작거나 같은 자연수 또는 0이다.
www.acmicpc.net
'Algorithm > Algorithm 문제' 카테고리의 다른 글
백준_11399 ATM (삽입정렬 & 구간합배열) (0) | 2024.01.14 |
---|---|
백준_1427 소트인사이드 (선택정렬) (0) | 2024.01.13 |
백준_2750 수 정렬하기 (버블정렬) (0) | 2024.01.11 |
백준_11286 절댓값 힙 (우선순위 큐&힙) (0) | 2024.01.10 |
백준_2164 카드2 (큐) (0) | 2024.01.10 |